Skip to content

Native columnar ingest: the declared property types are read once per call, not once per chunk (refs #315) - #386

Merged
tae898 merged 2 commits into
ArcadeData:mainfrom
humemai:perf/315-native-declared-once
Nov 22, 2026
Merged

tae898 merged 2 commits into
ArcadeData:mainfrom
humemai:perf/315-native-declared-once

Conversation

@tae898

@tae898 tae898 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

On the native wheel, a vector column (a list of lists loading into an ARRAY_OF_FLOATS property) crosses as a float32 matrix only when the property is declared, so the packer reads the declared types. It did that 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. I changed it to read once per call and share the answer between the chunks.

Reads of schema:types per call when a vector column needs the declared types, as read from the code:

Call Before After
insert_many, 3,500 rows, commit_every=1000 4 (one per chunk) 1
insert_columns that falls back to rows, 2,500 rows, commit_every=1000 4 (one for the columnar attempt, one per chunk) 1
insert_arrow or insert_dataframe whose batches fall back to rows 1 plus one per chunk of each batch 1
a call where no column needs the declared types 0 or 1 unchanged

How a stale answer is excluded:

  • One columnar.Declared belongs to one call. insert_many and insert_columns make it, and insert_table hands 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.
  • The ingest never changes the schema itself. The image takes the type with getType (a missing type is an error) and the bulk paths declare no property. The engine makes types and properties implicitly only for openCypher CREATE and MERGE. So the one way the schema changes inside a call is the caller's own code running while a generator of rows is read.
  • That is a statement on the handle. NativeDatabase now counts the statements it runs through command() (_command_count, one integer add in _exec), and Declared reads 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.
  • Not covered: a schema change made on another handle, thread or process while a call runs. The old per-chunk read could see it, as a race. I think that is fine for a bulk load, but it is a difference.

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_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.

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 wheel 26.11.1.post2 with only the four Python files of this PR swapped per arm (A the merge base 65e7c8f354, B the tip before the rebase a48eac4c0a, 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.

small is a schema of three types. wide adds 60 document types of 10 properties each, because one read of schema:types returns the whole schema, so a read costs more in a larger schema.

Schema Case Schema reads, A then B A, ms B, ms B/A (95% interval) Control C/A Verdict
small many_vec_1000 1, 1 5.04 5.04 1.006 (0.994 to 1.032) 0.997 GRAY
small many_vec_3500 4, 1 17.59 17.29 0.987 (0.980 to 1.004) 0.999 NO CHANGE
small many_vec_10000 10, 1 51.07 49.86 0.986 (0.968 to 0.991) 1.003 GRAY
small many_scalar_10000 0, 0 27.82 28.07 1.007 (1.005 to 1.014) 1.008 NO CHANGE
small cols_fallback_2500 4, 1 204.97 204.68 0.999 (0.996 to 1.010) 1.001 NO CHANGE
wide many_vec_1000 1, 1 6.48 6.51 1.003 (0.993 to 1.015) 0.997 NO CHANGE
wide many_vec_3500 4, 1 23.79 19.07 0.807 (0.789 to 0.815) 0.998 WIN
wide many_vec_10000 10, 1 72.81 51.39 0.717 (0.702 to 0.726) 1.004 WIN
wide many_scalar_10000 0, 0 27.99 27.98 1.006 (0.993 to 1.015) 1.000 NO CHANGE
wide cols_fallback_2500 4, 1 211.72 205.86 0.979 (0.971 to 0.984) 1.000 NO CHANGE

With three types a schema read is cheap and nothing moves. With the 60 extra types insert_many takes 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.post2 library (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.py and tests/test_native_columnar_pack.py. They count the schema reads at the statement (the handle's query with schema:types), never time:

  • insert_many, insert_columns with a row fallback and insert_arrow with a column that cannot cross each read once per call, and store what the JSON path stores.
  • A generator that creates the type and a vector property while the first chunk is read, and another property before the second, still sends every chunk as columns and reads twice, not three times.
  • Two successive calls each read the schema, and the second sees a property made between them.
  • Declared on 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 --files on them, and the four Declared tests against the old and the new columnar.py with 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

  • A regression test fails on the old code and passes on the new (the Declared tests do; the integration tests wait for CI)
  • The test suite that the change can affect passes (waits for the native CI run)
  • uvx pre-commit run --files <changed files> passes

@tae898 tae898 added python Pull requests that update python code performance Speed or memory of the bindings, with a measurement native The arcadedb package (native library build) labels Nov 13, 2026
@tae898 tae898 self-assigned this Nov 13, 2026
@tae898

tae898 commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

The timed A/B of the post3 candidate against the released post2 (results on #315) shows no measurable change for this PR: the native insert_columns figure with a vector column in 100 chunks has B/A 1.000 with an interval of 0.991 to 1.008. The schema reads per call drop from several to one, but the figure does not move on a one-type schema, and the change adds an integer to every native command. I am leaving it out of the post3 candidate for now. It would need a figure that shows a gain, for example a schema with many types, before it goes in.

@tae898

tae898 commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

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 26.11.1.post2, with only the four Python files this PR changes swapped in each arm. A is the merge base 65e7c8f354, B is the tip a48eac4c0a, and C is A again as the control. 12 interleaved rounds (A B C, then C B A) on the mini, not pinned to cores (see the edit note below), a bootstrap 95% interval over the rounds, and the rule of #317 (WIN: the upper bound is below 0.90. NO CHANGE: the interval is inside 0.97 to 1.03. Otherwise GRAY). The control stayed inside 0.97 to 1.03 on every row, and the study counts the schema reads of each arm.

small is a schema of three types. wide adds 60 document types of 10 properties each, because one read of schema:types returns the whole schema.

Schema Case Schema reads, A then B A, ms B, ms B/A (95% interval) Control C/A Verdict
small many_vec_1000 1, 1 4.98 4.94 0.993 (0.986 to 1.003) 1.001 NO CHANGE
small many_vec_3500 4, 1 17.39 17.05 0.981 (0.976 to 0.985) 0.998 NO CHANGE
small many_vec_10000 10, 1 49.80 49.20 0.989 (0.979 to 0.993) 0.999 NO CHANGE
small many_scalar_10000 0, 0 27.47 27.66 1.002 (0.998 to 1.016) 1.001 NO CHANGE
small cols_fallback_2500 4, 1 202.75 203.74 1.002 (0.996 to 1.007) 0.999 NO CHANGE
wide many_vec_1000 1, 1 6.43 6.41 0.999 (0.991 to 1.009) 0.998 NO CHANGE
wide many_vec_3500 4, 1 23.07 18.89 0.812 (0.807 to 0.820) 1.000 WIN
wide many_vec_10000 10, 1 71.00 51.06 0.716 (0.711 to 0.720) 0.998 WIN
wide many_scalar_10000 0, 0 27.62 27.73 1.003 (0.996 to 1.007) 0.998 NO CHANGE
wide cols_fallback_2500 4, 1 209.03 204.19 0.977 (0.970 to 0.980) 1.002 GRAY

What I read from it:

  • With three types a schema read is cheap and nothing moves, which matches the first A/B.
  • With the 60 extra types, insert_many of 3,500 rows takes 19% less time and of 10,000 rows 28% less. The saving grows with the number of chunks, as the read counts say it should.
  • The two cases that must not move (one chunk, and rows with no vector column) did not move, so the counter this PR adds to every native command does not show.
  • cols_fallback_2500 on the wide schema is 2% faster, GRAY by the rule.

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 26.11.1.post2 library because the branch predates the change to what arcadedb_n_tx returns, so it times the change as written, not a rebased branch. And 60 types of 10 properties is my own choice of a large schema.

Next I will run it again pinned, rebase the branch onto main, update the description, and take it out of draft.

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 Cpus_allowed_list: 0-19. The numbers are unchanged.

@tae898

tae898 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

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 Cpus_allowed_list: 0-19. The table is unchanged and the control was clean, but I will run it again pinned before this leaves draft.

tae898 and others added 2 commits November 22, 2026 23:02
…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]>
@tae898
tae898 force-pushed the perf/315-native-declared-once branch from a48eac4 to 39b0a4d Compare November 22, 2026 14:03
@tae898

tae898 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

The pinned run is done and it confirms the first one. Same study and arms as above (the published native wheel 26.11.1.post2 with only the four Python files of this PR swapped per arm (A the merge base 65e7c8f354, B the tip before the rebase a48eac4c0a, C is A again as the control), 12 interleaved rounds, a bootstrap 95% interval over the rounds, and the rule of #317). This time the process was confined to the two cores of one compare lane of the mini: its own record and the host worker's both say Cpus_allowed_list: 0,2. Two other studies ran on the other compare lanes (compare2, compare3) at the same time. The control stayed inside 0.97 to 1.03 on every row.

Schema Case Schema reads, A then B A, ms B, ms B/A (95% interval) Control C/A Verdict
small many_vec_1000 1, 1 5.04 5.04 1.006 (0.994 to 1.032) 0.997 GRAY
small many_vec_3500 4, 1 17.59 17.29 0.987 (0.980 to 1.004) 0.999 NO CHANGE
small many_vec_10000 10, 1 51.07 49.86 0.986 (0.968 to 0.991) 1.003 GRAY
small many_scalar_10000 0, 0 27.82 28.07 1.007 (1.005 to 1.014) 1.008 NO CHANGE
small cols_fallback_2500 4, 1 204.97 204.68 0.999 (0.996 to 1.010) 1.001 NO CHANGE
wide many_vec_1000 1, 1 6.48 6.51 1.003 (0.993 to 1.015) 0.997 NO CHANGE
wide many_vec_3500 4, 1 23.79 19.07 0.807 (0.789 to 0.815) 0.998 WIN
wide many_vec_10000 10, 1 72.81 51.39 0.717 (0.702 to 0.726) 1.004 WIN
wide many_scalar_10000 0, 0 27.99 27.98 1.006 (0.993 to 1.015) 1.000 NO CHANGE
wide cols_fallback_2500 4, 1 211.72 205.86 0.979 (0.971 to 0.984) 1.000 NO CHANGE

On the wide schema insert_many takes 19% less time at 3,500 rows and 28% less at 10,000 rows, both WIN. The other 8 rows have B/A between 0.979 and 1.007 (2 of them GRAY because an interval edge is just outside the band).

I rebased the branch onto main (no conflicts, head 39b0a4d390), updated the description with these numbers, and am taking the PR out of draft so CI runs on it.

@tae898
tae898 marked this pull request as ready for review November 22, 2026 14:04
@tae898 tae898 added this to the 26.12.1 milestone Nov 22, 2026
@tae898
tae898 merged commit 6219570 into ArcadeData:main Nov 22, 2026
60 checks passed
@tae898
tae898 deleted the perf/315-native-declared-once branch November 22, 2026 14:43
@tae898

tae898 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

native The arcadedb package (native library build) performance Speed or memory of the bindings, with a measurement python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant