-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(uiGridAutoResize): Replaced timeout checker with watcher #6470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(uiGridAutoResize): Replaced timeout checker with watcher #6470
Conversation
…ight change with watcher
Can you add unit tests for your change? |
There are some unit test for original autoresize and that pass succesfully. But I will look at that later and I will try to add some meaningful test for this. |
There was already two tests here: src/features/auto-resize-grid/test/auto-resize-grid.spec.js I added other test cases, when element or container became narrower. And I added test cases for height change too. |
$watch is dirty code this pull request added more throttles |
@cybermerlin @falsyvalues What if I add some "denounce" functionality into watcher? It will fire on every event but it will resize grid only when you stop resizing window. I didn't want to make it worst. On our project it didn't have impact on performance and we get rid of timeout cycle every 250ms. But we don't have so big data. |
@tfilo I agree with @cybermerlin |
@falsyvalues If we get back to original source code with timeout cycle set to 250ms. It will be same performance as throttle with 250ms on watcher am I right ? So after considering all facts and suggestions I can come up with this solution. It will watch for change, if change occure it will unregister watcher, wait 250ms in case you are resizing window, than it will resize grid and register watcher again. From my point of view it will have negative impact on performance same way like original code has. But we get rid of 250ms cycle triggering even when you don't resize.
If you agree that is not sufficient can you @mportuga revert this merge to original code? In case you agree that we can use my suggested solution I will make commit with merge request. |
But I recommend use |
@cybermerlin window.on('resize', ... is bad idea because you can change grid container size by hiding side menu for example, and in this case there is nothing like windows resize event because windows size is still same. And with grid.container.on('resize'.. i am not sure if container emit any event on resize. But I am going look at that. |
@falsyvalues I tried today 16 columns with 2000 rows with my first suggested code and I don't have any issue with that in Chrome. How can I simulate this performance issue anyway ? |
I have commited another changes which should improve performance. If you have any better solution feel free to replace it. But I am out of options. See comments there. |
It's not the same, since timeout was called once and $watch is a continuous digest loop.
With $watch you can use throttle function and that is all you can get, so it is not so good solution imho. Best option it to react on event (maybe not window resize, since its a main case for throttle 😄) then get size (reflow triggered) then call refresh on grid. You can take a look on performance graph that I posted in #6499 and look for reflow triggers. P.S. I have not chance to review code yet. |
@falsyvalues thank for looking into it. Unfortunately I wasn't successful implementing this feature event based. So my last solution is still based on watcher. With some debounce like function which prevent from resizing grid while you are still resizing window or container. But it did not prevent from fireing watcher on every change. Now there is timeout 400ms on timer. If this will still cause performance problem. I can unbind watcher when timeout set. And bind it on timeout again. So it will prevent watcher to be triggered more often. But it will still based on watcher :( |
In uiGridAutoResize there was cyckle which checked every 250ms for width or height change. I have implemented this same feature but based on watcher. So it shouldn't be affecting the performance of your site or application negatively.