Skip to content

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

Draft
tae898 wants to merge 4 commits into
mainfrom
perf/388-residual-jvm-new-edge
Draft

tae898 wants to merge 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

Not measured yet, so no figure here. The change removes crossings, which the test counts, and I have not timed it. The speed claim waits for a timed A/B of a candidate wheel against 26.11.1.post3, as CONTRIBUTING asks.

The figure for that A/B: 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

🤖 Generated with Claude Code

@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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
…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 <noreply@anthropic.com>
@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 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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