html: fix language model cache evicting at capacity instead of overflow#309174
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
html: fix language model cache evicting at capacity instead of overflow#309174yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Conversation
The `getLanguageModelCache` eviction check used `===` to compare the current entry count against `maxEntries`, which meant the oldest entry was evicted as soon as the cache reached its configured maximum size. At steady state the cache therefore held only `maxEntries - 1` entries. Changing the condition to `>` ensures eviction only occurs when the count exceeds `maxEntries`, allowing the cache to retain entries up to the intended limit.
17e221c to
af13d33
Compare
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.
The
getLanguageModelCachefunction in the HTML language server uses===to check whether the current entry count equalsmaxEntries. This causes the cache to evict the oldest entry as soon as it reaches its configured maximum size, meaning the cache only holdsmaxEntries - 1entries at steady state instead of the intendedmaxEntries.For example, with
maxEntries = 10(the value used throughout the HTML server), only 9 parsed documents are ever cached simultaneously. The 10th entry immediately triggers eviction, bringing the count back to 9 before any subsequent access.Fix: Change the condition from
nModels === maxEntriestonModels > maxEntries. Eviction now only occurs when the cache has grown beyond its limit, allowing up tomaxEntriesentries to be retained.Before:
After:
Affected caches in the HTML language server (all with
maxEntries = 10):documentRegionsinlanguageModes.tsembeddedCSSDocumentsandcssStylesheetsincssMode.tshtmlDocumentsinhtmlMode.tsjsDocumentsinjavascriptMode.ts