Skip to content
This repository was archived by the owner on Nov 21, 2026. It is now read-only.
This repository was archived by the owner on Nov 21, 2026. It is now read-only.

to_json_list() on a small result: a 64 KB buffer per batch and an extra Java call cost ~40% of a one-row read #144

Closed

Description

@tae898

Found by the graph point-lookup investigation (laptop, relative only, balanced power profile). RowBatcher.nextJsonBatch allocates new StringBuilder(64 * 1024) on every call, and ResultSet.iter_json_batches calls it until it returns [], so a one-row result makes two JVM crossings, two str() conversions, two json.loads, and two 64 KB allocations. In Java the materialization is 3.9-4.3x the bound engine lookup (the 64 KB buffer alone 2.5-2.7x; JFR: 99% of allocation in AbstractStringBuilder.(int)); through Python a bound openCypher point lookup plus to_json_list() is 0.037 ms, of which the engine is 0.0034 ms. Fix: default-sized buffer, and stop after a short batch (nextJsonBatch returns fewer than max rows only when the set is drained): 0.59-0.62x end to end (0.037 -> 0.022 ms), identical rows, no slowdown on a 9,892-row scan (0.97-1.00x). Also: batch_size below 1 returned no rows at all; it is now refused. The benchmark's embedded graph arm materializes every timed read this way, so the fix also reaches the published embedded numbers at the next measurement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions