Repository navigation
JVM insert_many: homogeneous chunks cross as typed columns, not as JSON text - #392
Conversation
…nd the JSON route (refs #388) Parity (differential) tests for a typed-column route of the JVM insert_many that does not exist yet, so they fail on the parent: each stores the same rows with the typed route switched off and as shipped, and compares every record property by property through SQL (names, Java class of each value, value), for ints around 2^31 and 2^53 and 2^63, floats (NaN, infinity, subnormal, -0.0), strings, dates, date-times, nulls, None against a missing key, key order, mixed columns, date and Decimal inside lists, bytes, numpy scalars and aware date-times. Also the crossing counts, the order of mixed chunks, the commit boundary, the parallel mode, vertices, edge types, a duplicate key and a value no route can store. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… one JSON text (refs #388) A chunk whose rows are dicts with the same str keys in the same order, and whose columns each hold None and values of one exact type (int within 64 bits, float, bool, str, date, naive datetime), is read as columns: one numpy buffer per int, float or bool column, one StringColumn per string column, one TemporalColumn per date or datetime column, an Object[] only for a numeric column with a null. DocumentBatcher.insertManyColumns (and the parallel twin) builds the documents from them, and stores a whole number as the JSON text route did, an Integer when it fits an int and a Long beyond, so the stored type of a schemaless property does not depend on the route (insert_columns is unchanged and keeps Long). Every other chunk keeps the JSON text and the per-row fallback exactly as before: the whole chunk is judged first, from the types alone, before any bridge array is built. Bridge jar and Python only, no native image. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… its whole numbers Long, as the per-row path stores them (refs #388) The first CI run of the typed route (tagged 26.11.1, workflow_dispatch 43588034127, all 9 finished legs) failed 5 tests of tests/test_insert_many_typed_columns.py, the same 5 on every leg. Cause and evidence: - The parity failures (all_kinds-free, all_kinds_with_nulls-free, parallel all_kinds_with_nulls) differ in one value: row 11 (i = 0, f = -inf). The old route sends a row with a NaN, an infinity or a subnormal double down the per-row path (bulk_row_ok is False for rows 6, 9, 10 and 11 of that data, checked by script), and the per-row path stores a Python int as a Long. The text route stores the same number as an Integer. insertManyColumns narrowed every whole number to an Integer, so that one row differed. This is not engine-version specific: the per-row path is Python-side. - Fix in the code, not the test: fillRow keeps the whole numbers of such a row a Long (carriedByText: a double[] or Object[] column that holds a non-finite or subnormal double in the row). The stored data of the typed route is now the old route's for every row. The A/B candidate wheel changes (one pass over the columns per row in fillRow). - Two tests asserted the wrong thing. insert_columns still stores a Long: the type declared id INTEGER, which converts a Long to an Integer on any entry point, so it now declares nothing. The homogeneous-load test hard-coded how JPype prints a Java Boolean ('false') and a String ('str'); it now asserts the classes and the lower-cased texts. - New parity cases pin the rule: whole numbers that fit an int beside NaN, infinity, both signs of the smallest subnormal, the largest subnormal, the smallest normal value, -0.0 and a plain float, with and without nulls, on both the sync and the parallel route. - Docs: bulk-loads.adoc and the insert_many docstring state the exception. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
85332a9 to
38f015b
Compare
…o typed column carries reads no column (refs #388) The first timed A/B of the typed-column route (pull request #392, 2026-11-22) found two costs beside the wins: * A call of one row took 1.9 to 2.5 times as long as on the JSON route: the typed route builds one bridge array per column, the names array and the columns array, whatever the row count. * 100,000 rows with a Decimal column, which keep the JSON route, were about 5 percent slower: every chunk read the columns before the Decimal one to find out that the chunk cannot cross. The new tests count routes and reads, never time: the route of a call of one row, the route at the threshold and one row below it, the short last chunk of a load (JSON text beside typed chunks, same stored values as the old route), the parallel mode, and that a load with a Decimal column reads no column on any chunk (also bytes, list, dict, tuple and a numpy scalar in the first row). One more test pins what stays as it was: a Decimal behind a None in the first row is still found by reading the columns. The tests that compare the two routes on a handful of rows now open the typed route to a chunk of any size (an autouse fixture), so they keep testing it once a threshold exists. On this commit 11 of the new tests fail and the other 88 of the file pass (run on an overlay of arcadedb-jvm 26.11.1.post4 with the bridge jar of the branch). The next commit makes them pass.
…nd a first row no typed column carries refuses the chunk at once (refs #388) Two regressions of the typed-column route, from its first timed A/B (pull request #392, 2026-11-22): 1. One-row calls. The typed route has a fixed cost per call that the JSON text does not have: one bridge array per column (a str column is a StringColumn: two or three arrays and a constructor call), the names array and the columns array. The Java side is not slower. A chunk now needs at least _TYPED_MIN_ROWS = 64 rows to take the typed route; a smaller one is refused on its row count, before anything is read or built, and goes as JSON text as before this pull request. The threshold is per chunk, so the short rest of a load and a chunk cut by a commit boundary go as text too; the stored values do not depend on the route (the parity tests). The number comes from a probe of both routes at 1, 2, 4, 8, 16, 32, 64 and 128 rows for four row shapes (two bulk cores of the benchmark host, one process, not a timed study): the typed route was slower at 16 rows for all four (1.07 to 1.38 times the JSON route), still slower at 32 rows for three of them (1.01 to 1.16), and faster at 64 rows for all four (0.58 to 0.94). The crossover depends on the kinds of the columns, so 64 is the first probed size that slows no shape down. 2. Row sets that keep the JSON route. The route decision read every column in turn (a list of its values, the set of their types, for an int column a minimum and a maximum) until it met one it could not carry, on every chunk. Now it looks at the first row of the chunk first: a value there whose type no typed column carries (a Decimal, bytes, a list, a dict, a numpy scalar) refuses the chunk before any column is read. A column whose first value is None is still read as a whole, so the decision itself has not changed, only its order. Docs: the bulk loads page and the insert_many docstring name the 64 rows.
…unk with an odd row, and stops at the first reordered row (refs #388) The timed A/B of the typed-column route (runs r3 and r4 of 2026-11-22, both arms on the JSON text for these rows) measured rows of nine keys whose last row of each chunk has a key more 1.2 to 2.5 percent slower than before this pull request. The cost is the key check of the route decision: it built the key tuple of every row and one set of them, to learn at the last row that the chunk is not uniform. The new tests count the key tuples the decision builds (`tuple` as `core` sees it), never time: * a row with a key more or a key less, as the second, a middle or the last row of 200: only the keys of the first row are read; * a row that lists the same keys in another order: the check stops at that row; * a uniform chunk: the keys of every row are still compared (the order of the keys is part of what a record stores). On this commit 7 of the new tests fail and the other 100 of the file pass (run on an overlay of arcadedb-jvm 26.11.1.post4 with the bridge jar of the branch). The next commit makes them pass.
…before it compares them, and stops at the first row that differs (refs #388) A chunk takes the typed-column route only when every row has the keys of the first row, in its order. The check was one set of the key tuples of all rows: a tuple and a hash per row, for the whole chunk, also when the chunk then keeps the JSON text. In the timed A/B (r3 and r4, 2026-11-22) that made rows of nine keys whose last row of each chunk has a key more 1.2 to 2.5 percent slower than before this pull request, at 100, 10,000 and 100,000 rows. Now the number of keys is compared first (one pass, nothing built per row), which finds a row with a key more or a key less, and then the keys themselves, with no set, stopping at the first row that lists them otherwise. What the check accepts has not changed. A probe of the check alone (10,000 rows of nine keys, Python 3.12, two bulk cores of the benchmark host, not a timed study), in microseconds per chunk: the old check 2,796 when the last row has a key more; the new one 313 there, 314 when row 5 has it, and 2,814 against 2,673 for a uniform chunk (the count is one more pass on the route that then saves far more than that).
|
This is the result after two fixes that the first runs asked for. Setup:
Limits: one host; the JVM wheel only (the native wheel has its own columnar insert); the route threshold of 64 rows comes from a probe on the mini's efficiency cores, and the rows at 64 and 100 rows on the lane are the check of it. I am updating the description with this and taking the PR out of draft so CI runs on it. |
What does this PR do?
On the JVM wheel,
insert_manyturned every chunk of 10,000 rows into one JSON text (json_bulk_dumps_tagged), whichDocumentBatcher.insertManyJsonparsed again into a JSON tree and copied key by key. Now a chunk whose rows are dicts with the same str keys in the same order, and whose columns each holdNoneand values of one exact type (intwithin 64 bits,float,bool,str,date, or adatetimewithout a time zone), crosses as typed columns and no text: one numpy buffer per int, float or bool column, oneStringColumnper str column (whatinsert_columnsalready sends), oneTemporalColumnper date or datetime column (what #383 added), and a boxedObject[]only for a numeric column that holds a null. The new bridge entry points areDocumentBatcher.insertManyColumnsandinsertManyColumnsParallel, which sharefillRowwithinsertColumns. The synchronous and the parallel mode both take them.Every other chunk keeps the JSON text and the per-row fallback exactly as it was. The chunk is judged as a whole, from the types alone, before any bridge array is built: a row that lacks a key, has another one or lists the keys in another order, a column that mixes types (an
intbeside afloat), an int beyond 64 bits, aDecimal,bytes, numpy or pandas value, adatetimewith a time zone, a lone surrogate, a list, tuple or dict (adateinside a list included), and a float vector for anARRAY_OF_FLOATSproperty. A fallback chunk pays for the census and nothing else. The bridge jar and Python change; no native image is involved.One decision in the Java side is not obvious. The JSON text stores a whole number as an
Integerwhen it fits an int and as aLongbeyond (JSONObject.parseNumber), while a numpylong[]column would store aLongfor every number. A schemaless property would then be anIntegeror aLongdepending on which route carried its chunk, and a load with one fallback chunk would mix the two. SoinsertManyColumnsnarrows a whole number the way the text did.insertColumnsis unchanged and keepsLong(a test pins it).Nonestays a null property, never a missing one. A floatNaN, an infinity and a subnormal cross in adouble[]and are stored as the per-row path stores them (the old route sent those rows down the per-row path; the parity tests compare the stored values).What the change allocates per chunk of at most 10,000 rows and per column: one Python list of the column's values (references, not copies); an int, float or bool column also one numpy array and one
long[],double[]orboolean[]copy; a str column one UTF-8 byte buffer, oneint[]of offsets and aboolean[]when there is a null (theinsert_columnslayout); a date or datetime column one numpyint64array, onelong[]and aboolean[]when there is a null; a numeric column with a null oneObject[]of boxed values. The chunk is no longer held as one JSON text in Python, as a JavaStringcopy of it, and as a parsed JSON tree of all its rows. The memory of a load stays bounded by the chunk, as before (#294). I have not measured memory.Related issues
Refs #388 and #315.
Performance changes
Measured with a paired A/B on the mini:
arcadedb-jvm26.11.1.post4withcore.pyand the bridge jar swapped per arm (the jar compiled from each arm'ssrc/javaagainst the wheel's own jars; A's classes are byte-identical to the wheel's): A is the merge base097436a095, B is this PR6225d3f66f, C is A again as the control. 12 rounds, one JVM and one fresh database per arm and round, the median of the timed calls per case, a bootstrap 95% interval over the rounds, and the rule of #317, read row by row: a row counts only when its own control is inside 0.97 to 1.03. The process was confined to the two cores of one compare lane of the mini (Cpus_allowed_list: 0,2), no other study ran, and the host worker recorded 0 ms of thermal throttle. B is the tip6225d3f66f; the runs before it were on28fad45f96, and their B/A is in the last column.insert_manyrows)narrow_decimal_1narrow_decimal_100narrow_decimal_10000narrow_decimal_100000wide_extra_key_100wide_extra_key_10000wide_extra_key_100000narrow_1narrow_64narrow_100narrow_10000narrow_100000wide_1wide_64wide_100wide_10000wide_100000wide_null_1wide_null_nonull_1wide_null_city_1wide_null_64wide_null_100wide_null_10000wide_null_100000_TYPED_MIN_ROWS), every smaller chunk keeps the JSON text, and the records stored and the digests read back are equal in all arms.Limits: one host; the JVM wheel only (the native wheel has its own columnar insert); the route threshold of 64 rows comes from a probe on the mini's efficiency cores, and the rows at 64 and 100 rows on the lane are the check of it.
Docs
docs/modules/ROOT/pages/how-to/bulk-loads.adoc(the section on the values the bulk path carries) says which chunks cross as columns on the JVM package and which keep the JSON text. Theinsert_manydocstring says the same.README.mddoes not describe the transport.Checklist
uvx pre-commit run --files <changed files>passes (Bandit as CI runs it is clean too)