Skip to content

json: fix language model cache evicting at capacity instead of overflow#309176

Open
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/json-language-model-cache-capacity
Open

json: fix language model cache evicting at capacity instead of overflow#309176
yogeshwaran-c wants to merge 1 commit intomicrosoft:mainfrom
yogeshwaran-c:fix/json-language-model-cache-capacity

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

The getLanguageModelCache function in the JSON language server uses === to check whether the current entry count equals maxEntries. This causes the cache to evict the oldest entry as soon as it reaches its configured maximum size, meaning the cache only holds maxEntries - 1 entries at steady state instead of the intended maxEntries.

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 of languageModelCache.ts.

Fix: Change the condition from nModels === maxEntries to nModels > maxEntries. Eviction now only occurs after the cache has grown beyond its limit.

Before:

if (nModels === maxEntries) {

After:

if (nModels > maxEntries) {

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants