docs/solutions/performance-issues/2026-04-03-nodeid-duplicate-paste-should-scan-editor-once-per-fragment.md
withNodeId handled duplicate pasted ids correctly, but it paid for that
correctness in the dumbest possible way: one editor.api.some(...) scan per
candidate id during insert_node.
On a seeded duplicate paste, that turned one fragment insert into a pile of full-editor duplicate checks.
withNodeId hotspot.nodeid-fragment benchmark showed the live 5k duplicate-paste
lane at 20.06 ms, with 199 duplicate lookups costing about 13.89 ms.idExistsCache as enough. It only deduplicated repeated
checks for the same id. It did nothing for the common case where a pasted
fragment contains many distinct ids.nodeId work. The problem was not initialization anymore.Keep the single-pass inserted-node normalization, but replace per-id editor queries with one bounded prepass:
The implementation lives in:
The important constraint is behavioral: the rewrite keeps the same duplicate-id
semantics for inserted nodes and _id overrides.
The old path was roughly:
O(candidateIds * editorSize) duplicate existence workThe new path is:
So the repeated full-editor existence checks disappear.
On the same live 5k / 200-block duplicate-paste benchmark:
20.06 ms -> 13.79 ms199 -> 013.89 ms -> 0That cut about 6.27 ms from the real duplicate-paste lane without changing
the public NodeId API.