2019-09: isKeywordEnabled does an O(vocabularies) scan per keyword

Open Beginner friendly
#332 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
typescript
Domain
performance

Research direction

Start in src/services/vocabularies.ts and inspect isKeywordEnabled, especially its per-keyword vocabulary scan. Trace how vocabularyKeywords and activeVocabularies are used, then verify the existing behavior while replacing repeated scans with the suggested reverse lookup. Done means keyword checks preserve the current results without iterating all vocabularies each time.

Written by the indexing model from the issue text.

Description

Found while reviewing #308 (JSON Schema 2019-09 support).

Problem

isKeywordEnabled in src/services/vocabularies.ts iterates Object.entries(vocabularyKeywords) (all vocabularies and their keyword arrays) for every keyword check, and this runs per keyword per node during validation when vocabularies are active.

for (const [vocabUri, keywords] of Object.entries(vocabularyKeywords)) {
    if (keywords.includes(keyword) && activeVocabularies.has(vocabUri)) {
        return true;
    }
}
Suggested direction

Precompute a reverse keyword -> Set<vocabUri> map once at module load and do a single lookup.

Severity

Low — minor perf, only when activeVocabularies is present.

Dominant language
TypeScript
Stars
326
Forks
145
Avg merge
22h 10m
Merged PRs (30d)
9

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode-json-languageservice

All issues in microsoft/vscode-json-languageservice

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.