KEMBAR78
fix!: debounce updating overflow to improve performance by web-padawan · Pull Request #9618 · vaadin/web-components · GitHub
Skip to content

Conversation

@web-padawan
Copy link
Member

@web-padawan web-padawan commented Jul 2, 2025

Description

Fixes #9592

This reduces __detectOverflow() counts on initial render from 5 per component to 2:

  • Once after initial buttons render + a microtask
  • Second time on resize observer + a timeout

Also reverted change from #7312 which delayed setting _container as no longer needed, since the idea behind it was to postpone initial call to __detectOverflow() and it's now scheduled in a different way, so the IT still passes.

Note: needs some more testing with the Flow counterpart. ITs seem to pass with the latest version of the PR when running individual tests from IntelliJ, but I'm getting "script timeout error" from the waitForResizeObserver() when running ITs for the component from the command line (could be related to the change but IIRC it happened before).

Type of change

  • Behavior altering change

Note

This is a behavior altering chage as it affects timings, so I had to adjust e.g. visual tests and snapshot tests accordingly.
Could be especially relevant for Copilot which uses vaadin-menu-bar for the dev mode menu element internally.

Also this is likely to require some tweaks for both Flow component ITs and possibly also React components tests.

@web-padawan web-padawan requested a review from yuriy-fix July 2, 2025 11:04
@web-padawan web-padawan force-pushed the menu-bar-overflow-debounce branch from e7e185f to 2f65e55 Compare July 2, 2025 11:04
@web-padawan web-padawan force-pushed the menu-bar-overflow-debounce branch from 6cac3b3 to e965037 Compare July 2, 2025 11:24
@web-padawan web-padawan changed the title refactor: debounce updating overflow to improve performance fix!: debounce updating overflow to improve performance Jul 2, 2025
@web-padawan web-padawan force-pushed the menu-bar-overflow-debounce branch from 08d102d to ff2a92a Compare July 2, 2025 14:50
@web-padawan
Copy link
Member Author

UPD: seems like deferring first call to __detectOverflow() until first resize observer causes jumpiness with the Flow counterpart. I reverted related code so the method will be called twice (first in a microtask after rendering items and then on resize). This should still be quite an improvement compared to calling it 5 times which happens on main branch.

@web-padawan
Copy link
Member Author

Did some testing with the web component (creating 10 menu-bars on button click), here's the outcome.
The first screenshot on main branch has an indication of "long task" with more style recalculation calls.

So there is some improvement as a result but I wouldn't call it really significant.

Before

Screenshot 2025-07-03 at 10 19 54

After

Screenshot 2025-07-03 at 10 20 12

@web-padawan web-padawan marked this pull request as ready for review July 3, 2025 08:13
@web-padawan web-padawan requested a review from vursen July 3, 2025 08:13
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 3, 2025


beforeEach(() => {
menu = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>');
spy = sinon.spy(menu, '_hasOverflow', ['get', 'set']);
Copy link
Member Author

Choose a reason for hiding this comment

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

I wasn't able to properly spy on offsetWidth of the container. Also using _hasOverflow is only reasonable for initial render test but not for subsequent resizes, as in those cases it will be set at least twice: first by calling __updateOverflow() with empty array, and then with the actual items. But for this test IMO it's ok.

Copy link
Contributor

@yuriy-fix yuriy-fix left a comment

Choose a reason for hiding this comment

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

It seems that the performance has improved with the changes (tested initial render + resizing).

Before changes:
old-resize
old-detect-overflow

With changes:
new-detect-overflow
new-resize

Flow component tests are passing:
Screenshot 2025-07-03 at 16 03 29

@web-padawan web-padawan removed the request for review from vursen July 4, 2025 07:48
@web-padawan web-padawan merged commit c0e4876 into main Jul 4, 2025
10 checks passed
@web-padawan web-padawan deleted the menu-bar-overflow-debounce branch July 4, 2025 07:48
@vaadin-bot
Copy link
Collaborator

Hi @web-padawan and @web-padawan, when i performed cherry-pick to this commit to 24.8, i have encountered the following issue. Can you take a look and pick it manually?
Error Message:
Error: Command failed: git cherry-pick c0e4876
error: could not apply c0e4876... fix!: debounce updating overflow to improve performance (#9618)
hint: After resolving the conflicts, mark them with
hint: "git add/rm ", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 25.0.0-beta2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performance Issue for vaadin-menu-bar in _onResize

3 participants