editor: Cache getComputedStyle result in shadowCaretRangeFromPoint (#319803)#319804
Merged
alexdima merged 1 commit intoJun 5, 2026
Merged
Conversation
…icrosoft#319803) Reduces 6x redundant getComputedStyle() calls to 1x in the mouse move hot path. Each call forces a synchronous style recalculation — caching the result eliminates 5 unnecessary recalculations per mousemove event over shadow DOM editor content. No functional change — same properties read, same output, same behavior. Closes microsoft#319803 Co-authored-by: Muhammad Ishaq Khan <muhammadishaqkhan.2321@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors shadowCaretRangeFromPoint to avoid repeated getComputedStyle calls when building the font string.
Changes:
- Cache the
CSSStyleDeclarationreturned bygetComputedStylein a localcomputedStylevariable. - Read multiple font-related properties from the cached style instead of re-calling
getComputedStyleper property.
ulugbekna
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces 6 redundant
getComputedStyle()calls to 1 inshadowCaretRangeFromPoint(), which runs on every mouse move over the editor viewport's shadow DOM content.Problem
In
src/vs/editor/browser/controller/mouseTarget.ts:1136-1142, each CSS font property (font-style,font-variant,font-weight,font-size,line-height,font-family) was retrieved via a separategetComputedStyle(el, null)call. Each call forces a synchronous style recalculation, making this a measurable hot-path cost multiplied across every mouse move in the editor.Fix
Cache the
getComputedStyle()result once in a local variable, then call.getPropertyValue()on the cached result. The computedCSSStyleDeclarationobject is a live object, but since we only read properties (not mutating between reads), the cached reference is safe and correct.Impact
Before/After
This is a well-known browser perf best practice — MDN recommends caching getComputedStyle results when reading multiple properties.
Closes #319803
Co-authored-by: Muhammad Ishaq Khan muhammadishaqkhan.2321@gmail.com