Skip to content

fix: respect preferMap for empty maps in the streaming decoder - #122

Merged
mcollina merged 1 commit into
masterfrom
fix/stream-empty-map-prefermap
Oct 17, 2026
Merged

mcollina merged 1 commit into
masterfrom
fix/stream-empty-map-prefermap

Conversation

@mcollina

Copy link
Copy Markdown
Owner

The streaming decoder built empty maps with buildMap([], 0, context, true), which forces allString = true and therefore always returns a plain object — even when preferMap is enabled. The non-streaming path already respects preferMap for empty maps (buildMap([], 0, context)), so a streamed empty map decoded to {} while the same bytes decoded non-streaming gave new Map().

This one-line change drops the forced allString, so streaming empty maps now match the documented contract (preferMap → Map, otherwise a plain object).

I first attempted a larger change that applied the iterative decoder's direct-map-build to the streaming path, but profiling showed it regresses streaming (~2–3%): the streaming state machine feeds values one at a time, where per-item branching and the larger map frame outweigh removing the single buildMap pass. So I reverted it and kept only this minimal consistency fix.

4391 tests pass on Node 22/24/26.

@mcollina
mcollina merged commit c9785a6 into master Oct 17, 2026
20 checks passed
@mcollina
mcollina deleted the fix/stream-empty-map-prefermap branch October 17, 2026 19:12
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.

1 participant