Skip to content

The object table is an ordered tree, so no insert rehashes the whole table - #3411

Draft
matrixarkai wants to merge 6 commits into
mainfrom
perf/object-table-ordered-tree
Draft

matrixarkai wants to merge 6 commits into
mainfrom
perf/object-table-ordered-tree

Conversation

@matrixarkai

@matrixarkai matrixarkai commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Change

Store each kind's consolidated object table in a BTreeMap, so growing a table does not rehash every object while the engine write guard is held. Keep ordered iteration and key-based resume available to maintenance cursors.

Integrate the current main changes without replacing the SDK, recovery or compaction fixes. Update series mutation, reconciliation, layout reporting and compaction helpers to accept the ordered tables. Preserve borrowed-key writes. The separate context-node address side table retains its existing selected-key compaction path.

Validation

Local release-mode library/test-target typechecking passed on the main-integrated source after fixing the stale HashMap signatures and fixture declarations. Behavioral, allocation, serialization and recovery assertions were retained.

Head 6137625 passed 54 targeted release tests with alloc-probe enabled, including all six ordered-table checks, compaction slice/failure/restart, portable checkpoints and borrowed-key writes. The explicitly enabled allocation footprint guard passed too. Its ordered-table tests also passed in the raw CI log.

The previous head passed 53 targeted runtime checks, including compaction slice/failure/restart and portable checkpoint controls, but failed one whole-image round trip because its fixture used index version zero while the decoder stamps the current version. The fixture now starts at the current version, retaining its exact-byte assertion. Allocation-probe compilation also found stale hash-table helpers; those now use ordered containers. The hash-growth control remains separate from measured engine-tree bytes.

Two additional cost fixtures need correction for the smaller encoded images. Keep the codec saving minimum and all surface/placement ceilings, without imposing an upper limit on savings against a dated baseline. Increase the disabled-cadence fixture so it crosses its unchanged base-size precondition. Their exact files passed release library/test-target typechecking in the maintenance validation tree; execution of those corrections is pending.

CI on 613 failed its hard cost gate on the dated upper saving bound. Its advisory library run reported 4855 passed, 86 failed and 249 ignored, not a full-suite pass. Compared with the retained earlier run, the newly failing names are the two compression-sensitive fixtures and distributed chunking under append backpressure. That chunking test failed once and passed twice on the same local binary; its cause remains unresolved and is not waived.

Keep draft until corrected test execution and the applicable exact-head checks are inspected; request both reviewers and merge automatically after validation. No test exclusions or merge-policy changes are part of this change. Stage measurements do not establish completed-work latency or amplification targets.

The object-table selection is unconditional once merged, not an environment opt-in. This does not claim all other write-path side tables are ordered or that every maintenance-stage latency target has been reached.

…table

Each kind's object table was a hash table. A hash table doubles when it fills and a doubling
rehashes every row at once, and that ran under the engine's write guard, so the insert that
triggered it held every writer for as long as the rehash took, and the pause grows with the
table. An isolated HashMap<Arc<str>, 48 B> filled with 16-byte keys shows it at every doubling:
93 ms at row 57,344, 193 ms at 114,688 and 643 ms at 229,376 for a 300,000-row table, and
296 ms, 668 ms and 1,385 ms at rows 229,376, 458,752 and 917,504 for a 1.1M-row table.

The table is now a BTreeMap behind one type alias (ObjectTable). A tree grows one node per
insert, so no insert does work proportional to the table (the same fills into a BTreeMap show no
pause at any power-of-two row; the few outliers they do show are scheduling noise on a loaded
box), and its order is what a resumable maintenance cursor needs.

What it costs: a lookup is O(log n) string comparisons instead of one hash. Measured in the same
program on a loaded machine (load average 36, so the figures are an upper bound): random lookups
took 5.1 us against 1.45 us at 300,000 rows and 11.6 us against 2.0 us at 1.1M rows, and filling
the table took 1.4x (300,000 rows) to 2.9x (1.1M rows) as long. That is paid on every read and
write, against engine writes that cost hundreds of microseconds, so it is the trade this change
makes; the engine-level cost is still to be measured.

A decode still fills a table by ascending insertion, which leaves the left half of each split
empty, so the repack after a decode rebuilds the tables whose keys it re-points (strings,
features) and repacks the others in place.

Tests: the_object_table_is_an_ordered_tree pins the type alias and that no accessor spells the
hash map again. The string-table bytes-per-key test no longer reads a bucket capacity, since a
tree has none.

Measurement still owed before merge: the 300k fill and the max-write sweep, before and after,
and the engine-level read/write cost of the slower lookup.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@matrixarkai

Copy link
Copy Markdown
Owner Author

Submitted b4c10c6ab8a7fa38dd498faba5f505e5d49e9f33 on this draft's existing branch: the bucket-owner maintenance lookup now accepts ObjectTable, like CoreIndex.objects and the helpers it delegates to. The commit changes one signature line only.

The initial-head core job failed compilation. Its errors also reach the timestamped-series write helpers, lifecycle instant gathering, and footprint/test helpers that still require hash maps. This small correction does not complete that migration or establish a compiling branch. All-target checking, the new ordered-table guards, mixed-model restore/expiry/eviction/compaction tests, and engine-level latency/footprint measurements remain required.

Both superhaiou and bjmeetsfo are now actually requested as reviewers. The PR remains draft and unmerged. The remote branch advanced by a normal fast-forward; the owner's checkout, index, and local branch were not modified. No benchmark or passing-test claim is made for this new commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants