Repository navigation
perf: warm reads up fairly and visit incident edges without records - #85
Merged
Merged
Conversation
A member tree small enough to sit inside its edge record is a single leaf, but forEachKey and forEachValue still built a TreeCursor with its path arrays to read it. Loop over the leaf directly instead. Two-hop reads visit many small edges, and this was most of what they allocated.
The HStore adapter built a stream per probe, flat-mapped member streams into it and sorted through the stream API. Visit member ids into a reused long array and sort and count it in place, the same way the HyperGraphDB adapter fills one HashSet per probe.
Reads were warmed on 10% of their probes and large.scan on 40 passes, a few milliseconds of work. Most of the timed pass then ran before the JIT had compiled the read path, so the numbers mostly showed how quickly each engine's code got compiled. read.members came out several times below HStore's steady rate, and large.scan swung between runs by a factor of ten. Repeat each read workload, large.scan and latency.read untimed for at least two seconds first. Both engines get the same warm-up, and read.incidence.cold still runs cold.
Reader.incident builds a stream with an Incident record per edge, resolving role names for each one. Callers that only need the edge ids paid for all of that. Reader.forEachIncidentEdge hands the ids to a LongConsumer straight from the posting list, inline or promoted, with the same tenant check as incident.
The HStore adapter counted incident edges through Reader.incident, which allocated about 1.1 KiB per lookup against 98 B for HyperGraphDB. Count them through the new visitor instead, in the incidence, latency, mixed and two-hop workloads.
This was referenced Oct 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #84.
Why
After #83 and #84,
read.membersstill came out at about 0.6x HyperGraphDB. Profiling it outside the benchmark showed something else: once the JIT has compiled the read path, HStore enumerates members at about 6M per second and HyperGraphDB at 2 to 3M. The benchmark warmed reads up on 10% of their probes, andlarge.scanon 40 passes, a few milliseconds of work. Most of the timed pass ran before compilation finished, so the numbers mostly measured how fast each engine's code got compiled. That's also whylarge.scanswung between 0.4x and 8.6x from one run to the next.The same profiling turned up some per-read allocation worth removing.
What changes
large.scanandlatency.readnow repeat the whole workload, untimed, for at least 2 seconds first. Both engines get the same warm-up.read.incidence.coldstill runs cold.docs/benchmarks.mdexplains why.Tree.forEachKeyandforEachValueloop over an inline leaf directly instead of building aTreeCursorwith its path arrays for a single leaf.Reader.forEachIncidentEdge(atom, action). Hands the ids of the edges containing an atom to aLongConsumer, straight from the posting list, with the same tenant check asincident.Reader.incidentbuilds anIncidentrecord per edge, with its role names, which callers that only want ids don't need.long[]instead of a chain of streams.No format change.
Testing
TreeTest, ordered inline edges inInlineMembersTest, and inline and promoted posting lists inDatabaseTest. I broke each fast path on purpose (dropped or changed an entry) and the tests caught every case.Numbers
HStore against HyperGraphDB, scale 1, async, 64 MiB caches. The earlier column is the run behind #83, with the old warm-up. The new column is this branch: the median of 2 HStore runs and 3 HyperGraphDB runs.
read.incidenceread.membersread.comembershipread.twohoplatency.readlarge.scanHyperGraphDB's own numbers went up too once it was warmed up properly.
read.incidencewent from 51k to 455k per second, which is why its ratio dropped even though HStore got faster.A third HStore run stopped partway: background compaction found the active segment's file channel closed, and so did the shutdown after it. Eight more runs of this branch went through cleanly, and I haven't found what closed the channel in that one. The failure matches a problem that exists on main as well: when a thread is interrupted during file I/O, the JDK closes that channel for every thread. That gets its own issue and PR.
Measured on a laptop under load, so only the ratios mean much. The Azure rerun of the full comparison is still to do.