`parse_streamed_parallel` runs the loader's streamed parse (ADR-0011) of a
large file in regions of 512 KiB on the rayon pool, at most 4 at a time
(`PARALLEL_PARSE_THREADS`, and never more than the pool has). Each region is
the same builder, recorder and `Conversion::chunk`, started at a likely item
boundary found by a byte scan and stopped at the first boundary past the
next region's start; the results are appended in order and `finish` runs
once. A region's parse is speculative: the merge checks that it starts
where the region before ended and that nothing is carried into it
(`dates_carry`, `no_meta_carried`), and re-parses it from the real boundary
otherwise, so the scan never decides the result. Regions run in waves of
two per thread so peak memory does not hold every region's directives.
The loader uses it by default. `RLEDGER_PARALLEL_PARSE=0` turns it off and
`RLEDGER_PARSE_THREADS=N` changes the cap. Files under two regions, a
one-thread pool, the parser without its `parallel` feature, and wasm
targets keep the sequential streamed parse, whose instruction count is
unchanged: the region stop test is a const generic compiled out of it.
`rledger check`, first run, 16 cores, against `RLEDGER_PARALLEL_PARSE=0`:
29-39% less wall time, 7-26% more CPU time, 2-21% more peak RSS.
The oracle's nesting guard is released while the regions run: a rayon
thread waiting for them can take up another file's whole parse, which
would otherwise see this parse's depth and skip its reconciliation.
`streamed_parse_parity` compares the parallel parse with the whole-tree
parse on pools of 1, 2, 4 and 16 threads; the `compat.yml` job runs it with
`--features parallel` and asserts that regions ran, and
`fuzz_streamed_eq_whole` fuzzes it. ADR-0011 gains a "Parallel regions"
section.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
The loader now parses a single large file on up to 4 threads, by default, for files of 1 MiB or more. The output is byte-identical to the sequential parse.
parse_streamed_parallel(incrates/rustledger-parser/src/cst/convert/parallel.rs) works in three steps:Conversion::chunkas today. A region starts at its own boundary and stops at the first item boundary at or past the next region's start. No converter is duplicated.Conversion::finishruns once, exactly as for one region.Each region's parse is speculative. The merge checks two things for every region:
dates_carry,no_meta_carried).If either check fails, the region is re-parsed from the real boundary with the real carried state. The scan therefore only decides how much runs in parallel, never the result.
open_body_holds_a_failed_lineopenreport_no_metadata_continuationsno_meta_carriedmust be empty, otherwise the next region is re-parsed with itreport_invalid_datesdates_carryKindTokenIter::restartable_at)finish, onceCap and controls
PARALLEL_PARSE_THREADS = 4, and never more than the rayon pool has. That many pool tasks take region indices from a shared counter, in waves of two regions per thread.checkat 3.53 s sequential, 2.45 s on 4 threads and 2.16 s on 16. CPU cost was +17% on 4 threads and +80% on 16. Past 4 threads, the remaining wall time is the sequential rest of the load.RLEDGER_PARALLEL_PARSE=0turns the feature off.RLEDGER_PARSE_THREADS=Nchanges the cap.checkhas no--jobs-style option to hang one on, so the controls are env-only. They are documented indocs/commands/check.md.RLEDGER_PARSE_THREADS=1, a parser built without theparallelfeature, and wasm targets (not(target_family = "wasm")). A small file never even starts the rayon pool.parallelfeature, so the CLI and LSP get it.rustledger-wasm(wasm32-unknown-unknown) andrustledger-ffi-component(wasm32-wasip2) both build and use the sequential path.Bug found and fixed
The oracle's thread-local
NestingGuardconflicted with rayon work-stealing. A thread waiting on regions can steal another file's whole parse. That parse then saw the wrong nesting depth and skipped its error reconciliation. The guard is now released while regions run, and entered again only aroundfinish.Equivalence
streamed_parse_parityagainst the whole-tree parse: pools of 1/2/4/16 threads, region sizes from 1 byte to 4 KiB, cap 4 and uncappedrledger check --format jsonand exit code (earlier rounds)CI guards:
compat.ymlparse-error-parity job runs the parity test with--features parallel. It now also asserts that regions actually ran.fuzz_streamed_eq_wholecompares the parallel parse (1-byte and 48-byte regions, cap 4 and uncapped) alongside the streamed parse.What users get by default
rledger check --no-cache, first run, comparing the default (cap 4, 16-core pool) againstRLEDGER_PARALLEL_PARSE=0. Timing was gated on 1-minute load < 4. The 1-minute load was about 3.1–3.6, but the machine was shared (5- and 15-minute loads of 6–8 from other jobs), so absolute times are about 25% slower than in the earlier quiet runs. The relative numbers match the earlier noisier repeat.Other effects:
instr-bench check/*, measured on the same algorithm before the cap): −0.01% to +0.05% on clean workloads, and +0.12% / +0.19% onjunkline/errors.Docs
docs/commands/check.mdhas a "Parallel Parsing" section.docs/reference/performance.mdno longer says rustledger is single-threaded.How to test
🤖 Generated with Claude Code