Skip to content

ParseOptimizations

Defined in: src/core.ts:573

Opt-in parse-time performance tradeoffs.

IMPORTANT DESIGN RULE: only optimizations that carry a real COST as well as a benefit belong under optimizations. They are OFF by default so the caller consciously opts in and accepts the tradeoff. Optimizations that are ~free wins are ALWAYS enabled and never appear here (e.g. block-scalar accumulation, and key interning itself — only its memory cap is tunable, via keyCacheMaxKb below).

optional internStrings?: boolean

Defined in: src/core.ts:581

Intern repeated string scalar VALUES so equal values share one heap string (map keys are always interned regardless). Trades ~+16% parse CPU for up to ~-28% retained heap on data with many repeated string values; ~no benefit on unique-value data. Correctness-invisible either way (interned strings are ===-equal and immutable). Default: false.


optional keyCacheMaxKb?: number

Defined in: src/core.ts:594

Memory/CPU tradeoff for the per-parse key-intern cache (keyCache), in KB of cumulative distinct-key bytes. Raising it keeps more interned keys around, so more mapping keys across the document share one heap string (more cross-record dedup) at the cost of more retained memory; lowering it bounds memory tighter but gives up some of that dedup once the document’s distinct-key set exceeds the cap. Correctness is unaffected either way — a key seen after the cap is reached is simply left un-interned (still parsed to the right value, just not ===-shared with its other occurrences); nothing already cached is dropped. Default: 4096 (4 MB).