Skip to content

perf: reduce number of strings by 1200 - #327689

Merged
Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:perf/event-listener-stack-traces
Oct 5, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 5 commits into
microsoft:mainfrom
SimonSiefke:perf/event-listener-stack-traces

Conversation

@SimonSiefke

Copy link
Copy Markdown
Contributor

Details

Listener leak monitoring started capturing stack traces at 20% of its warning threshold:

if (this._leakageMon && this._size >= Math.ceil(this._leakageMon.threshold * 0.2)) {
	contained.stack = Stacktrace.create();
	removeMonitor = this._leakageMon.check(contained.stack, this._size + 1);
}

However, LeakageMonitor.check() ignores every call below the full threshold:

const threshold = this.threshold;
if (threshold <= 0 || listenerCount < threshold) {
	return undefined;
}

if (!this._stacks) {
	this._stacks = new Map();
}

With the workbench threshold of 175, listeners 36 through 174 therefore retained unused stack strings such as:

Error
    at Stacktrace.create (.../vs/base/common/event.js:614:17)
    at ContextKeyService._event (.../vs/base/common/event.js:714:38)
    at ScopedContextKeyService._updateParentChangeListener (.../contextKeyService.js:384:53)

The graph shows ca. 1200 less error strings with this change:

Concatenated Error String Count

Other measurements*

  • Memory: Estimated reduction: 52,268 bytes (~51 KiB)
  • Startup performance −2.34 ms improvement, or −0.46%

*average of 17 runs, might not be 100% accurate

Copilot AI review requested due to automatic review settings July 27, 2026 19:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Defers listener stack capture until the configured leak-warning threshold, reducing retained error strings and memory use.

Changes:

  • Aligns stack capture with LeakageMonitor.check().
  • Adds threshold-boundary coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/vs/base/common/event.ts Delays stack capture until the warning threshold.
src/vs/base/test/common/event.test.ts Tests stack capture below and at the threshold.

Comment thread src/vs/base/test/common/event.test.ts Resolved
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Simon Siefke (@SimonSiefke) Thank you!

@dmitrivMS Dmitriy Vasyura (dmitrivMS) changed the title feature: reduce number of strings by 1200 perf: reduce number of strings by 1200 Oct 5, 2026
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit dae0d59 into microsoft:main Oct 5, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.142.0 milestone Oct 5, 2026
@SimonSiefke
Simon Siefke (SimonSiefke) deleted the perf/event-listener-stack-traces branch October 5, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants