perf/decoder quadratic scan - #15
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces resumable string parsing to the JSON decoder, allowing it to correctly handle string values that are split across multiple input chunks. The main changes include the addition of the
consumeStringResumableutility, updates to theDecoderandCursorclasses to track partial string parsing state, and comprehensive tests to ensure correctness for chunked and escaped string scenarios.Resumable string parsing support:
consumeStringResumablefunction insrc/utils/wire.tsto allow incremental/resumable parsing of string literals, supporting continuation across chunk boundaries and proper handling of escapes and UTF-8 validation. [1] [2] [3] [4]Decoderclass insrc/modules/decoder.tsto useconsumeStringResumableand maintain an internal#offsetfor tracking partial string consumption, enabling correct parsing when string tokens are split across chunks. [1] [2] [3] [4] [5] [6]Internal buffer management improvements:
Cursorclass insrc/modules/cursor.tsto track buffer ownership and optimize how new byte chunks are appended, minimizing allocations and supporting efficient incremental parsing. [1] [2] [3]Testing and validation:
tests/integration/decoder.test.tsto verify correct parsing of large strings, strings split across many chunks, escaped quotes at chunk boundaries, and full object values after chunked strings.consumeStringResumableintests/wire.test.ts, covering chunked string completion, escape handling, and deferred UTF-8 validation. [1] [2]These changes collectively ensure that the JSON decoder can robustly parse arbitrarily chunked input streams, especially for large or escaped string values.