Add incremental parse API and extract parser engines#5
Merged
Conversation
Split the completion and parse engines into dedicated files. Add parse-focused specs and benchmark coverage, and update the README to position .parse as the primary streaming API.
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.
What Changed
JsonCompleter.parseis the new fast path for callers that want Ruby values from partial JSON streams.On the benchmark in this PR, it is
8.93xfaster at p50 thancomplete + JSON.parseand reduces allocated objects4.66x(20419154->4381473)..parseis the primary streaming path: it returns the current Ruby value directly from partial input while maintaining parser state between calls, so each update processes only new data..completeremains for callers that specifically need completed JSON text.The implementation is split into:
ParserEnginefor incremental.parseCompletionEnginefor.completeScannersfor shared token scanningThe PR also separates parse/completion specs, adds a benchmark spec, and updates the README to position
.parseas the primary streaming API.Validation
bundle exec rubocopbundle exec rspecJSON_COMPLETER_BENCHMARK=1 bundle exec rspec spec/parse_benchmark_spec.rbBenchmark
Command:
for i in $(seq 1 10); do JSON_COMPLETER_BENCHMARK=1 bundle exec rspec spec/parse_benchmark_spec.rb; doneDefaults:
iterations=50,chunk_size=8(roughly 2 streamed tokens per update).Run Parameters
77690971250810Runtime Summary
parsecomplete + JSON.parse1.9712s17.7352s2.0006s17.8693s2.0251s18.1113s2.0525s18.1960s2.0799s18.2806s2.0070s17.9238sAllocation and Memory
parse4381473008448complete + JSON.parse2041915419660831160Comparison
8.68x8.93x9.10x9.13x9.16x8.93x4.66x