Skip to content

Conversation

@SimonSiefke
Copy link
Contributor

Overview

This changes the toDisposable function to use a class so that there is one dispose function on the class prototype instead of a dispose closure created for each toDisposable function call.

The memory savings seem to be ~1.2 MB.

Function overview chart

This function overview chart of vscode shows how many function instances exist of each function:

base

Notably at the top is createSingleCallFunction, which is used by toDisposable.

Heapsnapshot before

before2

Heapsnapshot after

after

Notable differences:

  • The number of Functions is reduced from 117165 to 96305
  • The number of closures (System Context) is reduced from 55728 to 35040
  • The number of { dispose } objects is reduced from 11342 to 1192
  • The number of FunctionDisposables increases from 0 to 10087
  • The memory savings seem to be ~1.2 MB.

mjbvz
mjbvz previously approved these changes Sep 22, 2025
Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Thanks!

@mjbvz mjbvz enabled auto-merge September 22, 2025 19:30
@vs-code-engineering vs-code-engineering bot added this to the September 2025 milestone Sep 22, 2025
@SimonSiefke
Copy link
Contributor Author

Hi @mattbierner,

Thanks for the review!

I'm currently wondering about the failing unit test. It seems there was this code in remoteIndicator.ts which caused this issue #142204 :

quickPick.onDidHide(itemUpdater.dispose);

Now this code doesn't exist anymore and it also seems a bit odd to me that someone would call dispose with undefined as this (except as a mistake maybe?).

Do you think the failing test can be removed? Thanks again.

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 22, 2025

Thanks, yes I think we should remove that test. Our other disposable types (Disposable, DisposableStore) would not work with this pattern. I don't think it makes sense to support it for toDisposable only

auto-merge was automatically disabled September 22, 2025 20:31

Head branch was pushed to by a user without write access

TylerLeonhardt
TylerLeonhardt previously approved these changes Sep 22, 2025
meganrogge
meganrogge previously approved these changes Sep 22, 2025
@mjbvz mjbvz enabled auto-merge September 22, 2025 22:26
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 23, 2025

Unsure about why the CI checks are failing. Re-running after merging to see if they are transient failures or need more investigation

@SimonSiefke SimonSiefke marked this pull request as draft September 24, 2025 10:29
auto-merge was automatically disabled September 24, 2025 10:29

Pull request was converted to draft

@SimonSiefke
Copy link
Contributor Author

Hm. Looks like it's always failing due to chat errors. I will try to see if I can reproduce the errors locally and maybe solve them.

@SimonSiefke
Copy link
Contributor Author

I checked and it's indeed the same error that also was in the unit test with the unbound this.

Typescript doesn't catch these errors, but I checked with the typescript eslint rule @typescript-eslint/unbound-method, which showed ~480 unbound method errors.

Still needeing to track down further which of these 480 errors are relevant and which are not.

mjbvz added a commit to mjbvz/vscode that referenced this pull request Sep 24, 2025
For microsoft#267785

This pattern is not safe when working with an `IDisposable`
@mjbvz
Copy link
Collaborator

mjbvz commented Sep 24, 2025

Ugh sorry this ended up being annoying and thanks for all the great follow up

I found one very obvious case that could have caused the failure here: #268202. Will see if I spot any others. Hopefully we can avoid having to update all 480 locations as many are false positives

@SimonSiefke SimonSiefke marked this pull request as ready for review September 24, 2025 21:07
@SimonSiefke
Copy link
Contributor Author

Thanks very much! The tests are passing now. It might just have been that one occurrence. I'd say this is ready to merge now - but with a small chance of potentially breaking something. :)

@mjbvz mjbvz enabled auto-merge September 24, 2025 21:44
Copy link
Collaborator

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

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

Thanks!

@mjbvz mjbvz merged commit 3bf92e7 into microsoft:main Sep 25, 2025
17 checks passed
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Nov 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants