Skip to content
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

Debounce the resize event handler #19612

Merged
merged 1 commit into from Jun 28, 2019

Conversation

Projects
None yet
2 participants
@rafeca
Copy link
Contributor

commented Jun 28, 2019

Context

Atom is currently listening to window resize events to store the window width/height and position and be able to restore the window dimensions when it gets reopened.

In order to do so, the resize handler is doing the following:

  • Get the current BrowserWindow object from the main process (synchronous IPC call).
  • Get the BrowserWindow size from the main process (synchronous IPC call).
  • Get the BrowserWindow position from the main process (synchronous IPC call).
  • Validate that data is correct.
  • Serialize the data into JSON and store it on localStorage (all synchronous).

All this processing usually takes 2-5ms on my high end machine, but under some circumstances (don't know what triggers it) it can take 40-50ms (or even up to 200-400ms, for example on Electron v4 because of electron/electron#19027). These times are way above the frame budget and cause very noticeable lagging on the UI when resizing.

Solution

The solution is a one-line change: just using a simple debouncer to only store the windows dimensions when the resizing has finished makes the UI lag-free.

Here there's a comparison video between current master and this PR, to see the noticeable difference (I didn't upload a gif since it cannot be appreciated well with that format due to the framerate).

@rafeca

This comment has been minimized.

Copy link
Contributor Author

commented Jun 28, 2019

Probably there are some failing tests... I'll leave CI to discover them for me 🙃

@rafeca rafeca force-pushed the debounce-resize-event branch from f81fe5a to 7593d49 Jun 28, 2019

@rafeca rafeca merged commit 401248d into master Jun 28, 2019

1 check passed

Atom Pull Requests #20190628.2 succeeded
Details

@rafeca rafeca deleted the debounce-resize-event branch Jun 29, 2019

@robertrossmann

This comment has been minimized.

Copy link

commented Jul 1, 2019

Wow, this simple change suddenly makes Atom feel like a native app. Nice and thanks! ❤️ 🚀

rafeca added a commit that referenced this pull request Jul 2, 2019

Merge pull request #19612 from atom/debounce-resize-event
Debounce the resize event handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.