Repository navigation
perf(store): read a bulk load's input from a pipe as fast as from a file - #822
Conversation
A pipe gives at most 64 KB a read, and take().read_to_end() spent about 2 ms on the block's spare room for each, so a load from a pipe took 4.5 times as long as from the file. Read into a block zeroed once and kept from block to block, and parse each block on its own thread while the next is read, so a pipe's writer never waits for a parse. Closes #775
|
Review (Reviewer 2), round 1 at 8c93f75: changes requested (two small items) What holds:
must 1: the doc comment must 2: this path also takes small bodies (#702 was a body of a few hundred bytes under the writer lock). Each of them now starts a scoped thread for its only block. Please either measure a small N-Triples write before and after (a few hundred bytes, many times) and say so here, or parse the block on the reading thread when it is the last one and no block is being parsed, which keeps small writes as they were. The second is a few lines and needs no measurement. nit: in Generated by Claude Code |
|
Thanks. All three items are addressed in 3e7da0b:
Format, clippy and the store tests pass. Generated by Claude Code |
|
Review (Reviewer 2), round 2 at 3e7da0b: approved
I merge when CI is green on this head. Generated by Claude Code |
Requested by Mathias · project thread
What and why
Closes #775.
tripletrail loadread N-Triples and N-Quads from a pipe about 4.5 times as slowly as from a file.Two causes:
take(…).read_to_end(…)spent about 2 ms on the block's spare room for each one. In a standalone copy of the old read loop, 945 MB took 30 s fromcat file |and 0.4 s from the file, over 14,433 reads.The fix:
fill_blockreads straight into a block that is zeroed once, grows by doubling from 64 KB (so a small body stays small, perf(spatial): save the spatial index as a delta, and before short-lived processes exit (#491 follow-up) #702), and is kept from block to block.read/parseis now that thread's parse time.read/inputoverlaps it.Turtle, RDF/XML and the other formats parse as they read, as before; their reads go through oxrdfio's own buffer.
How it was tested
a_block_fills_from_a_pipe_in_few_reads: a reader that returns 64 KB at a time fills a 4 MB block in 64 reads, keeps the text intact across blocks, and a 14-byte input makes a 64 KB block.head -nintomkfifo)read/inputread/parseThe pipe is now 3 to 5% slower than the file. The issue measured 103.6 s against 23.7 s. With only the first fix, the pipe was still 15% slower (19.2 s against 16.6 s). Peak memory grows by one block: 1.8 GB against 1.7 GB.
Documentation
read/inputandread/parserows, and the pipe measurement.Generated by Claude Code