Skip to content

html: fix language model cache evicting at capacity instead of overflow#309174

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

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

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

The getLanguageModelCache function in the HTML 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.

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 === maxEntries to nModels > maxEntries. Eviction now only occurs when the cache has grown beyond its limit, allowing up to maxEntries entries to be retained.

Before:

if (nModels === maxEntries) {

After:

if (nModels > maxEntries) {

Affected caches in the HTML language server (all with maxEntries = 10):

  • documentRegions in languageModes.ts
  • embeddedCSSDocuments and cssStylesheets in cssMode.ts
  • htmlDocuments in htmlMode.ts
  • jsDocuments in javascriptMode.ts

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.
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