Repository navigation
Native columnar ingest: the declared property types are read once per call, not once per chunk (refs #315) - #386
Conversation
|
The timed A/B of the post3 candidate against the released post2 (results on #315) shows no measurable change for this PR: the native |
|
I timed this branch again, this time also on a schema with many types, which is the figure my comment of 11-13 said it would need. It shows a gain there. Setup: the published native wheel
What I read from it:
Limits: one run on one host, and the processes were not pinned: the scheduler placed them on any of the 20 cores while a second study ran beside it. The control (A against A, same conditions) stayed within 1% of 1.00 on the two WIN rows, so the direction is safe, but I will run it again pinned before I take the PR out of draft. It is on the Next I will run it again pinned, rebase the branch onto Edit, 2026-11-22: I first wrote "on one pinned compare lane of the mini". That was wrong. The study left the pinning to the host worker, and the worker does not pin: the study's own record shows |
|
I corrected my comment above: the run was not pinned to cores. The study left that to the host worker, which does not pin, and its own record shows |
…nce per call, not once per chunk (refs ArcadeData#315) A vector column (a list of lists for an ARRAY_OF_FLOATS property) is laid out as a float32 matrix only when the property is declared, so the packer asks for the declared types, and it asked for every chunk of 1000 rows with a full read of schema:types. These tests count the schema reads per call (at the statement, on the handle's query), for insert_many, an insert_columns that falls back to rows, and an insert_arrow whose batches fall back to rows: one per call, where the old code made one per chunk. A generator that creates the type and a vector property on the first chunk and another property before the second must still see every chunk as columns, and two successive calls see a schema change made between them. Declared is unit-tested on a stub handle: it reads once, reads again after a statement ran on the handle, never reads when given its types, and asks again while the schema cannot be read. They fail on the current code (it reads once per chunk and has no statement stamp on the handle). Nothing is measured here. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…l, not once per chunk (refs ArcadeData#315) A vector column (a list of lists for an ARRAY_OF_FLOATS property) is laid out as a float32 matrix only when the property is declared, and the packer found that out with a full SELECT FROM schema:types (every type and property in one reply) for every chunk of 1000 rows of insert_many, and again for every batch of the row fallback of insert_columns, insert_arrow and insert_dataframe. Now one Declared belongs to one call: insert_many and insert_columns make it (columnar.declared_for) and every chunk shares it, and insert_table passes the types it already read to the row fallback of each batch. It is dropped when the call ends, so nothing is kept across calls. A schema change made while a call runs is still seen by the next chunk. The ingest itself never changes the schema (the image takes the type with getType, and only openCypher CREATE and MERGE make types or properties implicitly), so the one way is the caller's own code running while a generator of rows is read, and that is a statement on the handle: NativeDatabase counts the statements run through command() (_command_count), and Declared reads again when the count moved since it read. A query, a transaction call or a bulk crossing does not move it, so an ordinary load reads once. A read that fails is not kept, as before a chunk asked again. _insert_chunk takes the call's Declared before the chunk, because the ingest-integrity mutation tests wrap it as (type_name, *lead, chunk). The public insert_many is unchanged. Not measured yet: the speed claim waits for a timed A/B of a candidate wheel against 26.11.1.post2. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
a48eac4 to
39b0a4d
Compare
|
The pinned run is done and it confirms the first one. Same study and arms as above (the published native wheel
On the wide schema I rebased the branch onto |
|
One more fact about the pinned run, for the record: the host throttled during it. Three studies ran on the three compare lanes at once and the package reached 91 C; this run has 47.9 s of thermal throttle in its 23 minutes (from the host worker's end record). The arms are interleaved and the control stayed inside the band on every row, and the first run, which was not throttled, agrees with it within 1% on the two WIN rows, so I do not think it changes the result. |
What does this PR do?
On the native wheel, a vector column (a list of lists loading into an
ARRAY_OF_FLOATSproperty) crosses as a float32 matrix only when the property is declared, so the packer reads the declared types. It did that with a fullSELECT FROM schema:types(every type and property in one reply) for every chunk of 1000 rows ofinsert_many, and again for every batch of the row fallback ofinsert_columns,insert_arrowandinsert_dataframe. I changed it to read once per call and share the answer between the chunks.Reads of
schema:typesper call when a vector column needs the declared types, as read from the code:insert_many, 3,500 rows,commit_every=1000insert_columnsthat falls back to rows, 2,500 rows,commit_every=1000insert_arroworinsert_dataframewhose batches fall back to rowsHow a stale answer is excluded:
columnar.Declaredbelongs to one call.insert_manyandinsert_columnsmake it, andinsert_tablehands the types it read at the start to the row fallback of each batch. It is a local of the call, so nothing is kept across calls: a schema change made between two calls is seen by the second.getType(a missing type is an error) and the bulk paths declare no property. The engine makes types and properties implicitly only for openCypherCREATEandMERGE. So the one way the schema changes inside a call is the caller's own code running while a generator of rows is read.NativeDatabasenow counts the statements it runs throughcommand()(_command_count, one integer add in_exec), andDeclaredreads again when the count moved since its last read. A query, a transaction call or a bulk crossing does not move it, so an ordinary load reads once.Everything else is as before. A dict of known types (the DataFrame path) is still used as it is, and a read that fails is not kept, so the next column asks again, as the next chunk did.
_insert_chunktakes the call'sDeclaredbefore the chunk because the ingest-integrity mutation tests wrap it as(type_name, *lead, chunk). The publicinsert_manyis unchanged.Related issues
Part of #315.
Performance changes
Measured with a paired A/B on the mini, pinned to the two cores of one compare lane (
Cpus_allowed_list: 0,2): the published native wheel26.11.1.post2with only the four Python files of this PR swapped per arm (A the merge base65e7c8f354, B the tip before the rebasea48eac4c0a, C is A again as the control), 12 interleaved rounds, a bootstrap 95% interval over the rounds, and the rule of #317. The control stayed inside 0.97 to 1.03 on every row.smallis a schema of three types.wideadds 60 document types of 10 properties each, because one read ofschema:typesreturns the whole schema, so a read costs more in a larger schema.smallmany_vec_1000smallmany_vec_3500smallmany_vec_10000smallmany_scalar_10000smallcols_fallback_2500widemany_vec_1000widemany_vec_3500widemany_vec_10000widemany_scalar_10000widecols_fallback_2500With three types a schema read is cheap and nothing moves. With the 60 extra types
insert_manytakes 19% less time at 3,500 rows and 28% less at 10,000 rows. The four rows that must not move (one chunk, and rows with no vector column, in both schemas) have B/A between 1.003 and 1.007.Limits: one host, the
26.11.1.post2library (the arms are the branch before its rebase, because the overlay needs a library that matches the Python files), and 60 types of 10 properties is my own choice of a large schema. Memory was not measured: the change keeps one dict of declared types for the length of a call, where the old code built one per chunk.How I verified it
The tests came first, in their own commit, and extend
tests/test_native_columnar_insert.pyandtests/test_native_columnar_pack.py. They count the schema reads at the statement (the handle'squerywithschema:types), never time:insert_many,insert_columnswith a row fallback andinsert_arrowwith a column that cannot cross each read once per call, and store what the JSON path stores.Declaredon a stub handle: one read, a read again after a statement, never a read for a given dict, a failed read asked again.Locally I ran only light checks: compile, pyflakes, black, isort, ruff and bandit on the changed files,
uvx pre-commit run --fileson them, and the fourDeclaredtests against the old and the newcolumnar.pywith a stub handle (they fail on the old one and pass on the new one). The integration tests need the native library, so they run in CI only, and I have not seen them run yet.Docs
None. No public API or behavior changes.
Checklist
Declaredtests do; the integration tests wait for CI)uvx pre-commit run --files <changed files>passes