json: fix language model cache evicting at capacity instead of overflow#309176
Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
Open
json: fix language model cache evicting at capacity instead of overflow#309176yogeshwaran-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 triggered eviction as soon as the cache reached its maximum size. At steady state the cache therefore held only `maxEntries - 1` entries instead of the intended `maxEntries`. Changing the condition to `>` ensures eviction only occurs when the count exceeds `maxEntries`, allowing the cache to retain the full number of intended entries. The same fix was applied to the HTML and CSS language servers which contain an identical copy of this file.
930f5d8 to
28340bc
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 JSON 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.This is the same issue fixed in the HTML (
extensions/html-language-features) and CSS (extensions/css-language-features) language servers — all three share an identical copy oflanguageModelCache.ts.Fix: Change the condition from
nModels === maxEntriestonModels > maxEntries. Eviction now only occurs after the cache has grown beyond its limit.Before:
After:
With
maxEntries = 10(the default used in the JSON language server), the cache can now properly retain up to 10 parsed JSON document models instead of only 9.