Skip to content

perf(map,set): index node keys in a WeakMap for O(1) identity lookups - #744

Open
princejain756 wants to merge 1 commit into
eemeli:mainfrom
princejain756:fix/map-node-key-lookup
Open

princejain756 wants to merge 1 commit into
eemeli:mainfrom
princejain756:fix/map-node-key-lookup

Conversation

@princejain756

Copy link
Copy Markdown

Issue

fixes #740

LLM Use

I used an LLM tool when working on the code change, and wrote this PR description myself.

Description

YAMLMap and YAMLSet fall back to scanning every entry in this.values whenever this.values.has(mk) misses for a Node or Pair argument. During parsing, every new key node misses this.values.has(mk) on insertion, turning duplicate key checks in resolveBlockMap and resolveFlowCollection into O(N^2) work.

This tracks inserted key nodes in a per-collection WeakMap so has, getPair, get, delete, and keyOf resolve node identity in O(1) while verifying against this.values so replaced or deleted entries do not match. Parsing 100,000 mapping keys on Node locally drops from multi-second quadratic scaling to ~164ms.

This branch has not been deployed

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

(Performance) Duplicate keys are checked in quadratic time

1 participant