You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
import: a large event is re-parsed from the start on every read, so importing is quadratic in element size #1101
Found by the round-9 static review of #870 (PR #1094). Pre-existing on rewrite/main at 68be6f3: the file appears in that PR's diff only for a hunk at line 493, and this site is untouched.
The mechanism
crates/nostream-services/src/services/event_import_service.rs:390-437. ArrayStream::next_value parses the current element with a fresh serde_json::Deserializer::from_slice(&self.buffer[self.position..]) every call. On an incomplete element the arm
reads more and loops, and self.position has not advanced — only values.byte_offset() past a successful parse would have. So the element is parsed again from byte zero each time it grows.
A large event (a long article, a big NIP-46 payload) read in 8 KiB chunks is therefore parsed once per chunk over a growing prefix: import cost is quadratic in element size, and the peak allocation per parse grows with it.
What a fix needs
Either keep the parser state across reads (serde_json::Deserializer over a Read-like source that can be fed, rather than re-slicing), or find the element's end first — scan for the closing brace at depth 0, skipping strings and escapes — and parse the complete slice once. The second is a self-contained function and easy to test with an element larger than the read size; the existing tests already build arrays from a reader.
The reader finds each element's end as bytes arrive and parses it once; a 4 MiB event goes from about 1 GiB parsed to under 3× its size
A malformed element still fails early (it's tried each time it doubles), error messages are unchanged, and a number split across two reads no longer fails the import
8 new tests; all five CLAUDE.md checks pass (1816 tests)
Opened it for you, with your commit and authorship intact: #1235
I verified before pushing rather than taking the summary at face value: cargo fmt --all --check, both clippy invocations, cargo test --workspace --all-features (1816 passed, 0 failed — matching your number exactly) and the release build. The diff also scanned clean for hidden characters, and it touches no workflow, dependency or install path. Thanks for the careful write-up of the doubling probe; that is the part that makes the linearity claim checkable.
Landed on rewrite/main in 5ac6996 via #1235 — your commit was carried with its authorship intact, and the memory-buffering edge Greptile flagged on that path is fixed on top. Thank you.
Activity
AgrimTawani commentedon Nov 23, 2026
Hey @cameri, I'd like to take this one since I was just in the import code for #1097. Is it still open?
cameri commentedon Nov 23, 2026
@AgrimTawani Assigned to you. Thanks.
AgrimTawani commentedon Nov 23, 2026
Hey @cameri, the fix is ready on my fork; I still can't open the PR myself: rewrite/main...AgrimTawani:nostream:fix/1101-import-scan-once
CLAUDE.mdchecks pass (1816 tests)chappie-daemon commentedon Nov 23, 2026
Opened it for you, with your commit and authorship intact: #1235
I verified before pushing rather than taking the summary at face value:
cargo fmt --all --check, both clippy invocations,cargo test --workspace --all-features(1816 passed, 0 failed — matching your number exactly) and the release build. The diff also scanned clean for hidden characters, and it touches no workflow, dependency or install path. Thanks for the careful write-up of the doubling probe; that is the part that makes the linearity claim checkable.fix(import): parse each JSON array element once, however many reads i…
chappie-daemon commentedon Nov 23, 2026
Landed on
rewrite/mainin 5ac6996 via #1235 — your commit was carried with its authorship intact, and the memory-buffering edge Greptile flagged on that path is fixed on top. Thank you.