Skip to content

Menus: create the hide and toggle actions of menu items when first used - #350405

Draft
Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/menu-hide-actions-lazy
Draft

Federico Brancasi (federicobrancasi) wants to merge 1 commit into
mainfrom
fbrancasi/menu-hide-actions-lazy

Conversation

@federicobrancasi

Copy link
Copy Markdown
Member

Every build of menu actions (IMenuService.getMenuActions, IMenu.getActions) gave each item two actions to hide it: hide, with a localized label, and toggle. Only toolbars and a few context menus use them, but they were created for every item of every build. The command palette, for example, builds its whole menu, thousands of items, for each query.

This PR creates them on first access and keeps the instances, so repeated reads return the same actions.

isHidden stays a value read when the menu is built. Before, it read the toggle action's checked, which toAction copies once, and compareActions in the Source Control view compares it between builds to notice that an item was hidden or shown. Running the toggle still reads the current state, as before.

No issue is associated; this came from profiling.

Measured on my machine

  • In the app (Code OSS dev build, scripted scenarios that run commands from the command palette; window CPU profile): createMenuHide took 15 to 42 ms per scenario, most of it from the command palette.
  • Node benchmark of the old and new createMenuHide, with the real toAction and localize, 2,500 items like the command palette, median of 9 runs of 100 builds:
Before After
One build of 2,500 items 1.73 to 1.79 ms 0.74 to 0.76 ms

Toolbars read toggle for the items they show, so they still create it; the saving is where actions are built but their hide actions aren't read, such as the command palette.

Why behavior is unchanged

No consumer of hideActions copies, spreads or serializes it; they pass it on or read its properties:

  • MenuItemAction and SubmenuItemAction store it, and an alt action passes it on.
  • ToolBar in src/vs/platform/actions/browser/toolbar.ts reads toggle, toggle.checked, hide, isHidden and isModifiedFromDefault.
  • menuActivityBar.ts reads toggle.
  • compareActions in src/vs/workbench/contrib/scm/browser/util.ts compares isHidden, which is why it stays a value.
  • A few places pass action.hideActions through to a new action.

How to test

No test is added: callers see the same actions and values. The existing tests of menus and toolbars cover hiding and toggling.

Command Result
./scripts/test.sh --run src/vs/platform/actions/test/common/menuService.test.ts --run src/vs/platform/actions/test/browser/toolbar.test.ts --run src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasRegistryService.test.ts --run src/vs/sessions/test/browser/sessionActivityBar.test.ts --run src/vs/sessions/contrib/sessions/test/browser/sessionsList.test.ts --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/hostFilter.contribution.test.ts --run src/vs/sessions/test/browser/mobileTitlebarPart.test.ts --run src/vs/workbench/contrib/sessions/test/browser/parts/sessionHeader.test.ts passed, 806 passing
node_modules/.bin/tsc --project ./src/tsconfig.json --noEmit --skipLibCheck no errors in the changed files (9 errors in src/vs/platform/agentHost/, from my local Copilot SDK package being older than the one on main)
node_modules/.bin/oxlint src/vs/platform/actions/common/menuService.ts passed

Every build of menu actions created two actions per item to hide it,
with a localized label, although only context menus use them. The
command palette builds its whole menu for each query. Create them on
first access; isHidden stays the value read when the menu is built.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant