Skip to content

JVM: Vertex.new_edge resolves both ends and creates the edge in one crossing (refs #388) - #396

Merged
tae898 merged 4 commits into
mainfrom
perf/388-residual-jvm-new-edge
Nov 22, 2026
Merged

tae898 merged 4 commits into
mainfrom
perf/388-residual-jvm-new-edge

Conversation

@tae898

@tae898 tae898 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

On the JVM wheel, Vertex.new_edge() resolved both ends of the edge by record id in Python: getIdentity, isValid, lookupByRID and asVertex for the source, getIdentity and isValid for the target, then newEdge. That is seven JPype calls for one edge, where the native wheel makes one (#317).

Now it is one call to a new method of GraphCalls (src/java/com/arcadedb/python/GraphCalls.java):

public static Edge newEdge(Database db, Vertex source, String label, Identifiable target, Object... props)

The rules are the ones the Python code had, moved into Java. A source with a valid identity is looked up again by it when a database is given, inside the active transaction, so a vertex object read before another edge was committed does not fail with ConcurrentModificationException (the case of tests/test_stale_vertex_new_edge.py); otherwise it is used as it is. The target goes in as its identity when that is valid, and the engine loads it. Whether the edge is bidirectional is still the edge type's. The property values are converted in Python as before and cross as the varargs. The seven-call route is kept only as the fallback when the bridge jar is missing (_graph_calls() returns None), as the other readers of that file do.

Related issues

Refs #388 and #315. This is not one of the ten ranked rows of #388: I found it reading the same code for what the ten leave out.

Performance changes

Measured with a paired A/B on the mini: arcadedb-jvm 26.11.1.post4 with graph.py and the bridge jar swapped per arm (the jar compiled from each arm's src/java against the wheel's own jars; A's classes are byte-identical to the wheel's). A is the merge base 097436a095, B the tip 0c33e351ce, C is A again as the control. 16 rounds, one JVM and one fresh database per arm and round, each case's value in a process the trimmed mean of its timed batches, a bootstrap 95% interval over the rounds, and the rule of #317. The process was confined to the two cores of one compare lane of the mini (Cpus_allowed_list: 0,2), one other study ran on a second lane for its last 9 minutes, and the host worker recorded 13 ms of thermal throttle.

Case A, µs per edge B, µs per edge B/A (95% interval) Control C/A (95% interval) Reading
new_edge_plain_1 51.53 46.15 0.879 (0.770 to 0.970) 0.940 (0.887 to 1.125) information
new_edge_plain_100 17.01 8.77 0.517 (0.495 to 0.538) 1.009 (0.955 to 1.025) not a result by the rule: control outside the band
new_edge_plain_10000 19.23 10.96 0.560 (0.550 to 0.588) 1.003 (0.985 to 1.012) WIN
new_edge_props3_1 61.10 55.16 0.870 (0.819 to 0.954) 0.947 (0.890 to 1.180) information
new_edge_props3_100 23.32 14.72 0.629 (0.616 to 0.644) 0.988 (0.965 to 1.020) not a result by the rule: control outside the band
new_edge_props3_10000 26.45 17.76 0.679 (0.636 to 0.697) 1.000 (0.968 to 1.010) not a result by the rule: control outside the band
batch_plain_10000 8.59 8.79 1.017 (0.976 to 1.075) 1.000 (0.921 to 1.058) information
batch_props3_10000 11.60 11.57 0.984 (0.948 to 1.057) 1.002 (0.928 to 1.030) information
  • new_edge_plain_10000 has a clean control and is a WIN: 44% less time per edge.
  • On the other three rows B/A is 0.517 to 0.679 (no upper bound above 0.697), but the control interval leaves 0.97 to 1.03 by up to 1.5 points, so by the rule they are not a result. The study's own exit status is 3 for that reason. I show them because the effect is many times the control's spread.
  • A single edge per transaction (0.879 and 0.870) and the untouched graph_batch().new_edges path (1.017 and 0.984) are information only: one call is too short and a batch too variable to hold a 3% band in this design. Neither points to a regression.
  • Counted, not timed: one new_edge makes 7 calls into the JVM in A and 1 in B, and the edges written are the same in every arm (record ids, both ends, class, properties).
  • With begin and commit included, the whole transaction per edge has B/A 0.570 to 0.700 on the four rows (information).

This is an overlay on the released wheel, not a candidate wheel against 26.11.1.post3 as I first registered: the engine jars are the same file in all arms, which removes the build as a variable.

The figure as registered before the run: Vertex.new_edge(label, target) with no properties and with three properties (a string, an int and a float), for 1, 100 and 10,000 edges between vertices read once, each batch in one transaction, on a vertex type that has one edge type. The unit of one operation is one new_edge call, reported per edge. Wheel: arcadedb-jvm. The parity digest covers, for every edge, the property map, the Java class of the edge and the record ids at both ends, read back after the commit. The no-change control is graph_batch().new_edges for the same edges (a path this change does not touch), and an A/A pair.

Memory: the change allocates the property list that Python built before (two items per property) and nothing else. No batch or second copy of an input is held.

How I checked it

The tests come first in the first commit and the change in the second, so a run of the first commit shows them failing on the old code.

  • tests/test_vertex_new_edge_crossings.py (JVM wheel only, listed in NATIVE_NOT_APPLICABLE): one test counts the calls on proxies of the source and target vertex, the database and GraphCalls and expects exactly GraphCalls.newEdge (the old code makes seven calls on the Java objects and none on GraphCalls). The others compare the edge with one written by the former code, reproduced in the test: properties of six kinds, the Java class of the edge, both ends read back through get_out_edges and get_in_edges, the three forms of target (Python vertex, Java vertex, Java RID), edges without properties, a source read before two commits, and the class of the failure for a missing edge type, a value Java cannot take and an unsaved source.
  • test_without_the_bridge_class_new_edge_takes_the_plain_path_and_writes_the_same_edge puts None under the bridge class and checks that new_edge falls back to the seven calls and writes the same edge.
  • tests/test_stale_vertex_new_edge.py (both wheels) already covers the vertex that was read before other commits.
  • Run on this branch, light checks only: uvx pre-commit run --files on the changed files, Bandit as CI runs it, pyflakes.
  • Not run locally, so CI has to prove them: the Java compiles (no JDK on this machine), and the tests above on the JVM wheel. A draft pull request skips the platform legs, so they start when it is marked ready.

CI: to be filled in once the legs have run.

Docs

No page or the README describes how new_edge crosses, so none needs an update.

Checklist

  • A regression test fails on the old code and passes on the new (the first needs the CI run of the first commit to be seen)
  • The test suite that the change can affect passes (CI)
  • 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 jvm The arcadedb-jvm package (JPype build) labels Nov 14, 2026
@tae898 tae898 self-assigned this Nov 14, 2026
tae898 and others added 3 commits November 20, 2026 13:26
…s the one the seven-call path writes (refs #388)

The first test counts the calls on proxies of the source and target vertex, the database and GraphCalls: the parent makes seven calls on the Java
objects and none on GraphCalls.newEdge. The others compare the edge with one written by the former code (reproduced in the test) for the three forms
of target, edges with and without properties, a source read before other commits, and failures.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…rossing, through GraphCalls.newEdge (refs #388)

The lookup of the source by record id inside the active transaction and the target's identity were seven JPype calls (getIdentity, isValid,
lookupByRID, asVertex, getIdentity, isValid, newEdge). GraphCalls.newEdge does the same steps in Java, with the same rules: a source with a valid
identity and a database is looked up again, the target goes in as its identity when that is valid. The wheel carries its own bridge jar, so the
seven-call route is gone.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…in and commit), and edge lists are read through a fresh vertex (refs #388)

The tagged 26.11.1 JVM run failed three tests in every leg, all in tests/test_vertex_new_edge_crossings.py, and all three are the tests, not the new code:

- test_new_edge_is_one_call_into_the_bridge put a counting proxy in place of db._java_db before opening the transaction, and the transaction's own begin goes through DbCalls.stackMark(db), which JPype refuses for a proxy ("No matching overloads found"). The proxies are now on only around the new_edge call.
- test_the_edge_is_the_one_the_seven_call_path_writes and test_an_edge_without_properties_and_several_edges_of_one_vertex listed the edges of vertex objects read before the commit. A vertex object is the state it had when it was read: GraphEngine.getMostUpdatedVertex (26.11.1) hands it the newest record only inside the transaction that wrote it, so a stale object lists nothing (the same for the seven-call path, and the new_edge docstring says the object is not refreshed). The lists are read through a fresh lookup, and one assertion pins that the stale object is left as it was on both routes.

The code is unchanged: the properties, the edge class and the failure parity assertions of the same file passed in all legs.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@tae898
tae898 force-pushed the perf/388-residual-jvm-new-edge branch from 58ce315 to 3673950 Compare November 20, 2026 04:27
… missing (refs #388)

_graph_calls() answers None when the bridge jar is missing, which sends every caller down the plain path (main fixed the same
missing check for the reader calls in 84849b5). new_edge called GraphCalls.newEdge without that check and would raise an
AttributeError. It now takes GraphCalls.newEdge when the bridge exists and the former seven calls otherwise. The test puts
None under the bridge class and compares the edge with the one the bridge writes.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@tae898

tae898 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator Author

I timed this on the mini. Setup: arcadedb-jvm 26.11.1.post4 with graph.py and the bridge jar swapped per arm (the jar compiled from each arm's src/java against the wheel's own jars; A's classes are byte-identical to the wheel's). A is the merge base 097436a095, B the tip 0c33e351ce, C is A again as the control. 16 rounds, one JVM and one fresh database per arm and round, each case's value in a process the trimmed mean of its timed batches, a bootstrap 95% interval over the rounds, and the rule of #317. The process was confined to the two cores of one compare lane of the mini (Cpus_allowed_list: 0,2), one other study ran on a second lane for its last 9 minutes, and the host worker recorded 13 ms of thermal throttle.

Case A, µs per edge B, µs per edge B/A (95% interval) Control C/A (95% interval) Reading
new_edge_plain_1 51.53 46.15 0.879 (0.770 to 0.970) 0.940 (0.887 to 1.125) information
new_edge_plain_100 17.01 8.77 0.517 (0.495 to 0.538) 1.009 (0.955 to 1.025) not a result by the rule: control outside the band
new_edge_plain_10000 19.23 10.96 0.560 (0.550 to 0.588) 1.003 (0.985 to 1.012) WIN
new_edge_props3_1 61.10 55.16 0.870 (0.819 to 0.954) 0.947 (0.890 to 1.180) information
new_edge_props3_100 23.32 14.72 0.629 (0.616 to 0.644) 0.988 (0.965 to 1.020) not a result by the rule: control outside the band
new_edge_props3_10000 26.45 17.76 0.679 (0.636 to 0.697) 1.000 (0.968 to 1.010) not a result by the rule: control outside the band
batch_plain_10000 8.59 8.79 1.017 (0.976 to 1.075) 1.000 (0.921 to 1.058) information
batch_props3_10000 11.60 11.57 0.984 (0.948 to 1.057) 1.002 (0.928 to 1.030) information
  • new_edge_plain_10000 has a clean control and is a WIN: 44% less time per edge.
  • On the other three rows B/A is 0.517 to 0.679 (no upper bound above 0.697), but the control interval leaves 0.97 to 1.03 by up to 1.5 points, so by the rule they are not a result. The study's own exit status is 3 for that reason. I show them because the effect is many times the control's spread.
  • A single edge per transaction (0.879 and 0.870) and the untouched graph_batch().new_edges path (1.017 and 0.984) are information only: one call is too short and a batch too variable to hold a 3% band in this design. Neither points to a regression.
  • Counted, not timed: one new_edge makes 7 calls into the JVM in A and 1 in B, and the edges written are the same in every arm (record ids, both ends, class, properties).
  • With begin and commit included, the whole transaction per edge has B/A 0.570 to 0.700 on the four rows (information).

An earlier run of this study is not a result: it ran while two other studies held the other lanes, the host throttled, and every control row was out of band. I changed the design after it (interleaved cycles, more rounds, the one-edge and batch rows as information) and wrote that into the study before this run.

I am updating the description with this table and taking the PR out of draft so CI runs on it.

@tae898 tae898 added this to the 26.12.1 milestone Nov 22, 2026
@tae898
tae898 marked this pull request as ready for review November 22, 2026 15:27
@tae898
tae898 merged commit 76ce6ef into main Nov 22, 2026
112 of 114 checks passed
@tae898
tae898 deleted the perf/388-residual-jvm-new-edge branch November 22, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jvm The arcadedb-jvm package (JPype 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