Skip to content

graph_batch(): a batch of one edge takes about 2 ms and allocates about 41 MiB with the default arguments #431

Open

Description

@shaunpatterson

Summary

A graph_batch() has a fixed cost that does not depend on how many edges it gets. With the default arguments, a batch of one edge takes about 2 ms and allocates about 41 MiB on the JVM wheel, and about 2.5 ms on the native wheel. With batch_size=100 and chunk_cache_capacity=1000 the same call takes about 0.2 ms and allocates 0.6 MiB. A workload that opens a batch per request or per small group of edges (an agent writing a few relationships per turn, a stream writer) pays this on every batch, and the garbage makes the JVM heap grow (see the NMT note below). bulk-loads.adoc and the graph_batch() docstring describe both arguments but not this cost, so nothing tells a caller of small batches to change them.

Reproduction

Timing, both wheels:

import os
import tempfile
import time

import arcadedb

print(arcadedb.__backend__, arcadedb.__version__)
db = arcadedb.create_database(os.path.join(tempfile.mkdtemp(), "db"))
db.command("sql", "CREATE VERTEX TYPE V")
db.command("sql", "CREATE EDGE TYPE E")
with db.transaction():
    for _ in range(1000):
        db.command("sql", "CREATE VERTEX V")
rids = [str(r.get_rid()) for r in db.query("sql", "SELECT FROM V")]


def run(label, **options):
    def one():
        with db.graph_batch(**options) as batch:
            batch.new_edge(rids[0], "E", rids[1])

    for _ in range(200):  # warm up
        one()
    start = time.perf_counter()
    for _ in range(1000):
        one()
    micros = (time.perf_counter() - start) / 1000 * 1e6
    print(f"{label:45} {micros:7.0f} us per one-edge graph_batch")


run("default")
run("batch_size=100, chunk_cache_capacity=1000", batch_size=100, chunk_cache_capacity=1000)
native 26.11.1.post4
default                                        2474 us per one-edge graph_batch
batch_size=100, chunk_cache_capacity=1000       220 us per one-edge graph_batch

jvm 26.12.1.dev0
default                                        2235 us per one-edge graph_batch
batch_size=100, chunk_cache_capacity=1000       250 us per one-edge graph_batch

Allocation, JVM wheel (bytes the JVM allocates per graph_batch, summed over its threads with ThreadMXBean.getThreadAllocatedBytes):

import os
import tempfile

import jpype

import arcadedb

db = arcadedb.create_database(os.path.join(tempfile.mkdtemp(), "db"))
db.command("sql", "CREATE VERTEX TYPE V")
db.command("sql", "CREATE EDGE TYPE E")
with db.transaction():
    for _ in range(1000):
        db.command("sql", "CREATE VERTEX V")
rids = [str(r.get_rid()) for r in db.query("sql", "SELECT FROM V")]
bean = jpype.JClass("java.lang.management.ManagementFactory").getThreadMXBean()


def allocated():
    return sum(max(0, int(bean.getThreadAllocatedBytes(t))) for t in bean.getAllThreadIds())


def run(label, edges, **options):
    def one():
        with db.graph_batch(**options) as batch:
            if edges:
                batch.new_edge(rids[0], "E", rids[1])

    for _ in range(200):
        one()
    before = allocated()
    for _ in range(1000):
        one()
    print(f"{label:45} {(allocated() - before) / 1000 / 1024:9.1f} KiB per graph_batch")


run("no edge, default", False)
run("one edge, default", True)
run("one edge, chunk_cache_capacity=1000", True, chunk_cache_capacity=1000)
run("one edge, batch_size=100", True, batch_size=100)
run("one edge, both", True, batch_size=100, chunk_cache_capacity=1000)
no edge, default                                 8248.6 KiB per graph_batch
one edge, default                               41568.1 KiB per graph_batch
one edge, chunk_cache_capacity=1000              8829.9 KiB per graph_batch
one edge, batch_size=100                        33374.2 KiB per graph_batch
one edge, both                                    636.5 KiB per graph_batch

macOS arm64 (16 cores), Python 3.12, JDK 25 runtime of the JVM wheel; the JVM wheel was built from main at 0c3c7ec. Timings are single runs of 1,000 batches after 200 warm-up batches; the ratio held in four repeated runs (default 1.4 to 2.2 ms, tuned 0.19 to 0.30 ms).

Notes

  • An async-profiler allocation profile of the default one-edge loop puts most of the allocated bytes under com.arcadedb.graph.GraphBatch.<init> (long[], int[] and HashMap node arrays), which is engine code. The bindings pass batch_size and chunk_cache_capacity through unchanged, so the default sizes come from the engine.
  • Heap effect, JVM wheel: with -XX:NativeMemoryTracking=summary, 9,000 one-edge batches in a loop grew the committed Java heap by 7.6 GiB (the heap does not leak: used heap after a full GC stayed flat over 20,000 batches in a separate run), because the allocation rate makes G1 expand the heap.
  • Whether the engine should size these structures lazily is a question for ArcadeData/arcadedb. What belongs here is to say it: a short "many small batches" paragraph in bulk-loads.adoc and in the batch_size and chunk_cache_capacity entries of the graph_batch() docstring. I can send that as a PR.

Activity

  1. shaunpatterson commented on Nov 21, 2026

    @shaunpatterson
    Author

    Two more rows of the sweep, JVM wheel, same script: expected_edge_count=1 does not change the cost (41,565 KiB and about 1.6 ms per one-edge batch, the same as the default), and chunk_cache_capacity=1000 alone takes the allocation from 41,569 KiB to 8,832 KiB with the time unchanged (about 1.4 ms), so the chunk caches account for about 32 MiB of the 41 MiB; batch_size=100 alone leaves 33 MiB. Both arguments are needed to reach 0.6 MiB and 0.2 ms.

  2. added
    concurrencyThreads, transactions and conflicts
    jvmThe arcadedb-jvm package (JPype build)
    nativeThe arcadedb package (native library build)
    pythonPull requests that update python code
    on Nov 21, 2026
  3. added this to the 26.12.1 milestone on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

concurrencyThreads, transactions and conflictsin progressThe team is actively working on this issuejvmThe arcadedb-jvm package (JPype build)nativeThe arcadedb package (native library build)pythonPull requests that update python code

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions