Repository navigation
JVM GraphBatch: create_vertices and new_edges cross rows of exact scalars as typed columns, RIDs back as a long[] (refs #388) - #391
Conversation
…float vectors as typed columns, RIDs back as a long[] (refs #388, #315) The crossing tests count VertexBatcher.createVerticesColumns and EdgeBatcher.newEdgesColumns calls per chunk, the parity tests store the same rows through the typed route and through the JSON text route (the typed route switched off) and compare the property order and the Java class and text of every stored value, and every shape the typed route cannot carry is pinned to the route it keeps. These fail on 26.11.1.post3, where neither bridge method exists. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…alars and float vectors as typed columns, and the RIDs come back as a long[] (refs #388, #315) VertexBatcher.createVerticesColumns and EdgeBatcher.newEdgesColumns take the layout of DocumentBatcher.insertColumns (long[], double[], boolean[], StringColumn, FloatVectors.Matrix, with null flags) and make the engine call the JSON text route made, with the same key and value per property. A long that fits an int is boxed as an Integer, as the engine's JSON parser did, so the stored class is unchanged. Rows that are not all dicts of the same keys in the same order, or hold a value other than one kind of int, float, bool or str per property, keep the JSON text route. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ext, and the stored-record helper tolerates an edge without an id (refs #388) The first test read @Rid back through SQL and looked the texts up in that dict, which did not hold them under the same keys; it now loads each returned RID through the database and compares the id. The edge shape test with a None among dicts has an edge without an id, which the helper's sort key did not allow for. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1c6d9f9 to
8bd2487
Compare
…vertices and 32 edges for new_edges (refs #388, #315) The typed route builds the names array, the columns array and one bridge array per column on every call, and a StringColumn per str column, a fixed cost the JSON text does not have. A probe of both routes of this branch on the mini (cores 18 and 19, one process, the typed route forced off by making _scalar_columns answer None) found the typed route slower for a call of one row by 1.2 to 3.2 times for create_vertices and 1.5 to 3.8 times for new_edges. The crossovers differ by operation and shape. The first size where no probed shape is slower and none is slower above it is 32 edges for new_edges and 512 rows for create_vertices (the string-heavy l2 shapes are at 1.00 and 1.07 at 256 rows). A call of fewer rows (edges) keeps the old route, counted over the whole call and not per chunk, so a call over the floor crosses every one of its chunks typed. Edges with only empty property dicts keep newEdgesJoined at every size. The probe table is in the comment of the two constants. The routes of the calls below and at the floors are counted in new tests (never timed); the existing route tests switch the floors off, since they are about which shapes cross typed. The docs paragraph and the docstring of create_vertices say so.
…re any column is built (refs #388, #315) The first timed run of the study (ab391-r1) found create_vertices of 5,000 rows with a list-valued property, above the floor, 6.9 percent slower than before (B/A 1.069 [1.058, 1.106], control 1.004): _scalar_columns checked the shapes of all rows, then built the bridge array of every column in order (a long[] for id, a StringColumn for name) and only at the tags column found the list that cannot be typed, and threw the arrays away. A probe on the mini (one process, the old and the new code side by side) put that at 3.1 to 3.3 ms per call of 5,000 rows. Now the first row is looked at first (a value of a type no typed column holds refuses the call there), then the types of every column are decided one after the other from the types alone (_column_kind), and only when every column is carried is a bridge array built (_build_column). A list in the first row, or in every row, costs 0.001 ms. A list in a late row costs one pass over the types, 1.1 ms per 5,000 rows (a third of before). A carried call costs what it did: 3.80 ms against 3.77 ms. What the typed route accepts and refuses is unchanged (_scalar_column keeps its contract as the two steps in a row). The cost below the edge floor (e_since_1 1.051, e_since_16 1.031) is not a scan: before the floor test new_edges runs only `not any(properties)` (it stops at the first dict that holds a property) and the length compare, 0.4 to 0.5 microseconds per call in one process with the three versions side by side on one glue jar; the rest of the 0.8 and 2 microseconds of the study is not in the Python code, so the order of the checks is left as it is. New tests count the calls that read and build columns (never time): a list in the first row builds nothing and reads no column, a list in a late row decides three columns and builds none, rows of another shape build none, a carried call decides and builds every column, a call below either floor reads no column.
|
This is the result after the fix that the first run asked for (a call that the typed route cannot carry is now refused at the first value, before any column is built). Setup:
Limits: one host and two runs of 16 rounds (the earlier one on tip 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,
GraphBatch.create_verticessent every chunk of rows as one JSON text (VertexBatcher.createVerticesJson): Python wrote the text, the engine parsed it into aJSONObjectper row, a map per row was built from it, and the created RIDs came back as one;-joined text that Python split.GraphBatch.new_edgeswith properties did the same throughEdgeBatcher.newEdgesJson, and Python first built one dict per edge to carry the endpoints beside the properties.Now rows that are all
dicts with the same keys in the same order, each property holding one kind ofint,float,boolorstr(withNonefor a null), plus the float vectors that already crossed as aFloatVectors.Matrix, cross as one typed column per property, in the layout ofDocumentBatcher.insertColumns(long[],double[],boolean[],StringColumn, with aboolean[]of null rows for a column that has a null). The new bridge methods areVertexBatcher.createVerticesColumnsandEdgeBatcher.newEdgesColumns. They make the same engine call the text route made (GraphBatch.createVertices(type, Object[][])andnewEdge(src, type, dst, props...)), with the same name and value per property, so the batch settings (WAL, commit size, parallel flush, retries) apply as before. The RIDs of the vertices come back as onelong[]of[bucket id, position]pairs, which Python turns into the same"#12:345"texts, in the same order, as before. The new edge call keeps the RIDs as the two joined texts ofnewEdgesJoined, which is one bulk copy each.What keeps the old routes, so no input changes meaning: rows that are
Noneor have other keys or another key order, a property that holds a list, tuple, dict, date-time, date,Decimalorbytes, a column of mixed kinds (anintbeside afloator abool), a numpy scalar, a subclass, an integer beyond 64 bits, a NaN, an infinity, a subnormal, a lone surrogate, and an edge property named_srcor_dst. Those go to the JSON text route or to the property-matrix route exactly as they did, per chunk for vertices and for the whole call for edges (every edge chunk is built before the first crosses, so a chunk the typed route cannot carry starts the old route over with nothing buffered). Edges whose property dicts are all empty orNonenow usenewEdgesJoined, the call for edges without properties, which stores the same edges.One stored type is kept on purpose: the engine's JSON parser turns a number token that fits an int into an
Integer, so the text route stored a small Pythonintof an undeclared property asINTEGER, while the per-element paths andinsert_columnsstoreLONG. The typed route boxes alongthat fits an int as anIntegertoo, so the stored class does not change with the route. Whether the two should be unified is a separate decision.Related issues
Refs #388 and #315.
Performance changes
Measured with a paired A/B on the mini:
arcadedb-jvm26.11.1.post4withgraph_batch.pyand the bridge jar swapped per arm (the jar compiled from each arm'ssrc/javaagainst the wheel's own jars): A is the tip ofmain076d6d5674, B is this PR5c04af32fb, C is A again as the control. 16 rounds, one JVM and one fresh database per arm and round, 8 warm-up cycles then 30 timed cycles, the trimmed mean of the timings 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 tip5c04af32fb; the run before it was on4b64b81f9b, and its B/A is in the last column.4b64b81)v_l2_1v_l2_16v_l2_32v_l2_64v_l2_100v_l2_256v_l2_512v_l2_5000v_e2_50000v_e2_500000v_l3d_10000e_since_1e_since_16e_since_32e_since_64e_since_100e_since_5000e_empty_100e_empty_5000e_vertex_100e_vertex_5000c_edges_plain_5000c_count_5000c_list_5000c_list_first_5000c_list_row4000_5000c_list_last_5000e_since_1_calls2000newEdgesJoined) 0.352 and 0.309; withVertexobjects as ends 0.746 and 0.689.v_l2_50000.853 (0.835 to 0.870),v_l3d_100000.918 (0.899 to 0.949)). The controls of these rows (A against A) read up to 1.018 in this run, so I report the size of the effect and not a verdict.any(properties)and a length test before the old path; I did not isolate the cost to them. I left it, becauseany(properties)is also what sends[{}] * ntonewEdgesJoinedat every size.c_count_5000(create_vertices(type, 5000)) reads 0.993 (0.965 to 1.023) with a readable control (GRAY, the interval is a little wider than the band);c_edges_plain_5000has no readable control. A list in the first row (the refusal at the first value) reads 1.005 (0.990 to 1.025) and a list in every row 1.013 (0.991 to 1.027), both with a control outside the band; the run before read the list in every row at 1.069 (1.058 to 1.106) with a readable control, which is why the first-row refusal was added.Limits: one host and two runs of 16 rounds (the earlier one on tip
4b64b81, before the refusal fix); the JVM wheel only, the nativeGraphBatchis a separate change; the two floors come from a probe on the mini's efficiency cores (the table ingraph_batch.py), and the rows at the floor and one size below it are the check of it.What the change allocates, per chunk of
nrows andkscalar properties: one temporary list ofnreferences per property, one numpy array and itslong[]ordouble[]copy (8 bytes per value;nbytes for abool), aStringColumnfor astrproperty (the UTF-8 bytes and4 * (n + 1)bytes of offsets, asinsert_columnsmakes), aboolean[]ofnfor a property with a null, andntemporary key tuples for the same-keys check. The JSON text (one string of the whole chunk, then its UTF-8 copy), the parsedJSONArraywith aJSONObjectand a map per row, and the joined RID text are no longer allocated. TheObject[n][2k]matrix the engine takes is built as before. The returned RIDs are along[2 * n](16 bytes per vertex) before the list ofntexts. For edges, the columns of every chunk of the call are held until it ends (about 8 bytes per numeric value of the call), where the text route held one dict per edge for the whole call.Docs
docs/modules/ROOT/pages/how-to/bulk-loads.adoc(the paragraph on the property values ofcreate_verticesandnew_edges) and the docstrings ofcreate_verticessay which rows cross as typed columns.How I checked it
The tests are in the first commit and the change in the second, so a run of the first commit shows them failing on the old code.
4c84313): https://github.com/ArcadeData/arcadedb-python/actions/runs/43566990576. The test jobs fail; on linux/amd64 with Python 3.12 it is 3039 passed and 24 failed, and the failures include tests oftest_graph_batch_typed_jvm.pyandtest_graph_batch_vector_crossings_jvm.py.0af5e31): Test JVM run 43569512102, linux/amd64 with Python 3.12: 3060 passed and 3 failed. Two failures were bugs in my new tests (a read-back of@ridthrough SQL, and the sort key of the stored-record helper for an edge without an id), fixed in0854265. The third,tests/test_import_database.py::test_import_database_xml_vertices('FAIL' == 'OK', an engineIMPORT DATABASEof a local XML file), is not from this change: it also failed on the red run above, which has no production change, and on the Test JVM run of Native: GraphBatch.create_vertices sends columns and reads the RIDs from an int64 buffer #390, a native-only branch. A run on0854265is still to come.tests/test_graph_batch_typed_jvm.py(JVM wheel only, listed inNATIVE_NOT_APPLICABLE): crossing counts (onecreateVerticesColumnsornewEdgesColumnscall per chunk, none of the JSON calls, no property-matrix fallback), the returned RIDs againstSELECT @ridin row order and against the text route, parity of the stored records (typed route against the text route switched off) for vertices, vertices with vectors, a batch of one, a load over the chunk boundary and edges, and a test for every shape that keeps the text or matrix route (twelve vertex shapes, five edge shapes, a chunk that is not carried among carried ones, and the whole call going the old way for edges). The expectations oftests/test_graph_batch_vector_crossings_jvm.pymove fromcreateVerticesJsontocreateVerticesColumns, because the shapes there are now carried.uvx pre-commit run --files <changed files>and Bandit as CI runs it are clean. No native build is involved: the change is the bridge jar andgraph_batch.py, and the native wheel has its ownGraphBatch.Checklist
uvx pre-commit run --files <changed files>passes