Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds caching for resolved CSS variables to improve performance by avoiding repeated DOM manipulations and computed style queries. The cache stores the resolved string values of CSS variables that are looked up via getComputedStyle.
Key changes:
- Added a
_cssVariableCachemap to store resolved CSS variable values - Modified
resolveCssVariablemethod to check the cache before performing expensive DOM operations
| private _dummyElement: HTMLSpanElement; | ||
|
|
||
| private _ruleCache: Map</* className */string, CSSStyleRule[]> = new Map(); | ||
| private _cssVariableCache: Map</* variableName */string, /* value */string> = new Map(); |
There was a problem hiding this comment.
The CSS variable cache is never invalidated when themes change. CSS variables can have different values depending on the active theme. Since DecorationCssRuleExtractor is a static singleton (line 43 in viewGpuContext.ts), the cache will persist across theme changes and return stale values.
Similar to how TextureAtlas.clear() is called on theme changes (see atlas/textureAtlas.ts line 71-75), this cache should also be cleared when the theme changes. Consider adding a clear method to DecorationCssRuleExtractor and calling it when the theme changes, or subscribing to theme change events within the class itself.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
Cache resolved CSS variables
Fixes #286833