Repository navigation
fix(import): parse each JSON array element once, however many reads it spans - #1235
Conversation
…t spans The array reader re-parsed an incomplete element from its first byte after every 8 KiB read, so a large event cost time quadratic in its size. It now scans for the element's end as bytes arrive, keeping the scan's state across reads, and hands the element to serde_json once it is complete. An unfinished element is also tried each time it doubles, from 64 KiB, so a malformed element whose brackets never balance still fails early instead of buffering the rest of the input; the tries keep parsing linear. Error messages for malformed and truncated input are unchanged, and a bare scalar split across two reads is no longer cut at the read boundary. Closes #1101 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge; the previous buffering issue is fixed, and no new actionable issues remain.
|
Greptile's P1 on #1235: excluding scalars from the doubling probe left the one element kind whose scan cannot see an end buffering until EOF. `[` followed by 4 MiB of `x` held all 4,194,305 bytes before the parser saw its first byte. Scalars now probe on the same schedule. The cost is that a scalar longer than FIRST_PROBE is refused rather than read: a number prefix parses as a whole value and the separator check then names the byte after it, which is the same early failure this path is for. THE 4 MiB regression test fails on the previous commit and passes here.
|
Confirmed and fixed in 897ceb0. The claim measured exactly: with the previous commit, a The fix is the one you asked for: scalars probe on the same doubling schedule. A number prefix parses as a whole value, and the separator check then names the byte after it (
|
🦋 Changeset detectedLatest commit: 897ceb0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Closes #1101.
Contributed by @AgrimTawani, who cannot open the PR himself; the commit here is theirs, unmodified, cherry-picked from
AgrimTawani/nostream:fix/1101-import-scan-once(cf7b034) with its authorship intact.The mechanism
ArrayStreamre-parsed an incomplete array element from its first byte after every 8 KiB read, so a large event cost time quadratic in its size. The reader now finds each element's end as bytes arrive — tracking string contents, escapes and bracket depth — and hands the element toserde_jsononce its last byte is in. An unfinished element is still parsed each time its length doubles, which bounds what a malformed element buffers to about twice the offset of its fault and keeps total parsing linear. Error messages are unchanged; a bare number split across two reads is no longer cut at the boundary.Evidence
event_import_service.rs, its tests, one changeset).CLAUDE.mdchecks, run against this exact tree:cargo fmt --all --check, both clippy invocations,cargo test --workspace --all-features,cargo build --workspace --all-features --release— results in the comments below.