Repository navigation
fix: memory leak in menu hidden defaults - #348413
Dmitriy Vasyura (dmitrivMS) merged 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the menu-service change to reduce retained cache entries.
No open issues 🎉
What changed in this PR
This PR reduces memory retention in the menu service by removing redundant visible-default cache entries, so disposed dynamic commands no longer leave those keys behind.
Changes:
- Cache only hidden (
true) defaults and delete entries for visible (false) defaults. - Add regression tests for default changes, user overrides, disposed registrations, and replacement registrations.
No actionable findings remain. Tests were not run during this review.
| File | Description |
|---|---|
src/vs/platform/actions/test/common/menuService.test.ts |
Adds coverage for cache retention and hidden-state behavior. |
src/vs/platform/actions/common/menuService.ts |
Deletes false-default entries instead of retaining them. |
Review effort: Balanced
There was a problem hiding this comment.
🤖Generated by Copilot
Thanks Simon Siefke (@SimonSiefke) — this looks good to me.
Correctness. setDefaultState has a single caller (createActionGroups), and every reader of _hiddenByDefaultCache goes through _isHiddenByDefault, which already returns get(key) ?? false. So deleting the key instead of storing false doesn't change isHidden, updateHidden or isModifiedFromDefault. It also behaves the same when one command is registered twice in the same menu with different defaults, because the last write wins either way. The change just stops the map from growing with a false entry for every visible menu item, which includes dynamic commands that are later disposed.
Validation (local, at 7ab102f):
node test/unit/node/index.js --run src/vs/platform/actions/test/common/menuService.test.ts(Node unit runner) → 27 passing.- With only
menuService.tsreverted to the merge base (and the compiled output checked): "does not retain visible defaults from disposed registrations" and "removes a cached true default when a registration is replaced" fail. Their diffs show the retainedfalseentries. All other tests, including "updates hidden defaults while preserving user overrides", still pass. Restoring the change brings it back to 27 passing. pnpm run oxlinton both changed files → clean.pnpm run typecheck-client→ clean.
Non-blocking notes:
- A
trueentry for a hidden-by-default registration that is later disposed is still kept. The number of such entries is limited by how many distinct menu/command pairs are declaredisHiddenByDefault, and this was already the case before. Not something this PR needs to solve. If it ever matters, the follow-up should evict only keys whose registration was actually removed, for example by tracking disposal ofMenuRegistry.appendMenuItemregistrations. Clearing ononDidChangeMenuwouldn't work: that event reports only menu IDs, and clearing the cache would also drop live defaults for items whosewhenis currently false. - Two of the tests read
menuService['_hiddenStates']['_hiddenByDefaultCache']behind an eslint-disable. That's fine for a targeted retention test, but it will need updating if those private fields are renamed.
Full review report (plan, evidence, review rounds): https://aka.ms/publish?a=75a9e684-8496-4bfb-81a6-f9741f2d38be&v=bf6f0c77-6542-48dd-82dd-21864c119c7a
|
Simon Siefke (@SimonSiefke) Thank you! |
Details
The menu service caches false defaults under combined menu and command IDs. The cache outlives dynamic command registrations and keeps their key strings after the commands are disposed.
Change
Store only true hidden defaults and delete false entries, since a missing entry already means false.
Before
When registering commands, opening the Command Palette, and disposing the commands 17 times, the cache holds 1,052 redundant false entries. These include 17 disposed-command keys occupying 1,020 bytes. Total string growth is 200,784 bytes and 5,056 strings.
After
The cache has zero visible-default entries, including zero disposed-command keys. Total string growth is 155,664 bytes and 4,380 strings; other UI allocations remain.
Test Video
menu-hidden-defaults-native.webm
AI disclosure: Model: GPT 6.1 Sol. Worktime: 15 min