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

Avoid menu layout trashing by moving DOM queries #432

Merged
merged 2 commits into from
Oct 7, 2022

Conversation

krassowski
Copy link
Member

@krassowski krassowski commented Oct 5, 2022

This improves menu opening and switching performance as proposed in #329 (comment).

How to test

  1. Link local copy of @lumino/virtualdom and @lumino/widget against JupyterLab HEAD
  2. Download gh-9757-reproducer.ipynb, optionally change n=100_000 (this is what I am using)
  3. Run all cells
  4. Open menu in the menu bar over File and move to Edit and then View
  5. (optionally) record performance profile and compare the Recalculate Style event duration

Switching Menu (menubar)

Chrome (x6 CPU slowdown)

Before ~1300ms After ~1070ms (two layouts fewer)
Screenshot from 2022-10-05 22-11-20 Screenshot from 2022-10-05 22-25-42

Firefox (no throttling)

Before ~15ms After ~14 ms (two style computations fewer)
before after-ff

Opening Context Menu

Chrome (x6 CPU slowdown)

Before ~530 ms After ~360ms (one layout fewer)
Screenshot from 2022-10-05 22-10-14 Screenshot from 2022-10-05 22-27-14

@krassowski krassowski added the bug Something isn't working label Oct 5, 2022
@krassowski krassowski force-pushed the menu-prevent-layout-trashing branch 2 times, most recently from 2587990 to 3fd6930 Compare October 5, 2022 23:37
@krassowski krassowski added the performance Addresses performance label Oct 5, 2022
The DOM queries will execute before subsequent DOM modifications
to avoid layout trashing when opening or switching menus.
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @krassowski
The impact is really impressive on Chrome.

I left a couple of questions.

packages/widgets/src/menu.ts Outdated Show resolved Hide resolved
packages/widgets/src/menu.ts Outdated Show resolved Hide resolved
packages/widgets/src/contextmenu.ts Outdated Show resolved Hide resolved
@krassowski krassowski force-pushed the menu-prevent-layout-trashing branch 2 times, most recently from 7d427b8 to a50616a Compare October 6, 2022 20:36
@krassowski
Copy link
Member Author

Green now. The test failure was actually just my mistake when porting the tests not an actual issue in the code 🤦

Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @krassowski

@fcollonval fcollonval merged commit 55e87ca into jupyterlab:main Oct 7, 2022
@krassowski
Copy link
Member Author

Thank you @fcollonval. Do you think that we can backport this on 1.x and include in JupyterLab 3.5? It includes a new public API member, so I am not sure here.

@fcollonval
Copy link
Member

Thank you @fcollonval. Do you think that we can backport this on 1.x and include in JupyterLab 3.5? It includes a new public API member, so I am not sure here.

Sure thing

Extending or adding API is allowed as they do not break backward compatibility - especially in this case as they are not really meant to be used outside of Lumino.

@fcollonval
Copy link
Member

@meeseeksdev please backport to 1.x

@lumberbot-app
Copy link

lumberbot-app bot commented Oct 10, 2022

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout 1.x
git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 55e87caa277ac3ae3d15b8c5da75e78d54b069ff
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
git commit -am 'Backport PR #432: Avoid menu layout trashing by moving DOM queries'
  1. Push to a named branch:
git push YOURFORK 1.x:auto-backport-of-pr-432-on-1.x
  1. Create a PR against branch 1.x, I would have named this PR:

"Backport PR #432 on branch 1.x (Avoid menu layout trashing by moving DOM queries)"

And apply the correct labels and milestones.

Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon!

Remember to remove the Still Needs Manual Backport label once the PR gets merged.

If these instructions are inaccurate, feel free to suggest an improvement.

krassowski added a commit to krassowski/lumino that referenced this pull request Oct 10, 2022
…queries

* Move/cache DOM queries to prevent menu layout trashing

The DOM queries will execute before subsequent DOM modifications
to avoid layout trashing when opening or switching menus.

* Use simpler transient cache, move update requests

(cherry picked from commit 55e87ca)
krassowski added a commit to krassowski/lumino that referenced this pull request Oct 10, 2022
…queries

* Move/cache DOM queries to prevent menu layout trashing

The DOM queries will execute before subsequent DOM modifications
to avoid layout trashing when opening or switching menus.

* Use simpler transient cache, move update requests

(cherry picked from commit 55e87ca)
fcollonval pushed a commit that referenced this pull request Oct 11, 2022
)

* Move/cache DOM queries to prevent menu layout trashing

The DOM queries will execute before subsequent DOM modifications
to avoid layout trashing when opening or switching menus.

* Use simpler transient cache, move update requests

(cherry picked from commit 55e87ca)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working performance Addresses performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants