Skip to content

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

Description

@aeschli

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions