Skip to content

css: fix language model cache evicting at capacity instead of overflow#309175

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

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

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

The getLanguageModelCache function in the CSS 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, so the cache holds only maxEntries - 1 entries at steady state instead of the intended maxEntries.

The same issue was also present in the HTML language server (see companion fix in separate PR).

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 value used in the CSS language server), this means the cache can now properly retain up to 10 parsed stylesheet models instead of 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. As a result the cache only
held `maxEntries - 1` entries at steady state 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.
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