8000 feat(db): add bounded incoming-reference lookup to write transactions (#924) by adityamukho · Pull Request #926 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat(db): add bounded incoming-reference lookup to write transactions (#924) - #926

Merged
adityamukho merged 5 commits into
v3from
feat/924-incoming-refs
Nov 28, 2026
Merged

adityamukho merged 5 commits into
v3from
feat/924-incoming-refs

Conversation

@adityamukho
@adityamukho adityamukho commented Nov 28, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Adds incoming_refs(target, limits) to WriteTransaction and OwnedWriteTransaction: a bounded lookup of the (source, attribute) pairs that currently hold a scalar Value::Ref to an entity, as seen by the transaction (staged over pending over committed, or the working trees of a large transaction).

  • Separate max_links and max_records budgets. The outcome is IncomingRefs::Complete { links, records_examined } or IncomingRefs::Exhausted { budget, records_examined }; an exhausted lookup returns no links. Require Complete before cascading deletes.
  • Valid time is ignored. Keywords, strings, refs inside sets and rule-derived facts are not links.
  • The lookup writes nothing, allocates no dictionary id and takes no tx_count.
  • Access is local to the target in every layer: a new target-to-positions map for pending and staged facts, and a budget-checked VAET prefix walk for durable and large-transaction trees.
  • No file-format, WAL, grammar, Datalog or error-code change; no BrowserDb API.

Part of #924. The JVM binding and docs-site changes follow in their own repositories.

Type of change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Breaking change (requires migration or version bump)
  • Documentation / tests only

Binary size

x86_64 Linux dist build, Rust 1.99.1: base 73388aec5 1,246,760 bytes, branch 1,250,568 bytes (+3,808); gate 1,280,000 bytes. CI (Rust 1.100.1): 1,225 KiB of 1,250 KiB.

Write-path cost

Criterion medians, base against branch, two rounds with CPU/memory pinning swapped between them. No median regression above 5% on any of 65 workload IDs in either round. Largest increase: +4.01% (insert/explicit_tx/10k, round 1); that control is +2.9% to +4.0% at 1k, 10k and 1m and +0.6% to +1.0% at 100k. Largest increase on a ref-writing workload: +2.36% (incoming_ref_writes/staged/1000). Method and reproduction: docs/testing/924-incoming-refs.md.

Added pending-store memory per ref fact (10,000 ref facts): 13.13 B with one target, 13.24 B with 16 targets, 75.18 B with one target per ref.

All 65 workload IDs and scales (medians)
Workload ID Base r1 Branch r1 Change r1 Base r2 Branch r2 Change r2
incoming_ref_writes/checkpoint/1000 3.294 ms 3.283 ms -0.32% 3.318 ms 3.375 ms +1.74%
incoming_ref_writes/checkpoint/10000 35.54 ms 35.6 ms +0.18% 35.4 ms 36.17 ms +2.16%
incoming_ref_writes/pending/1000 3.72 ms 3.661 ms -1.60% 3.716 ms 3.671 ms -1.20%
incoming_ref_writes/pending/10000 40.99 ms 41.47 ms +1.16% 40.82 ms 41.21 ms +0.94%
incoming_ref_writes/promotion/1000 6.981 ms 6.893 ms -1.26% 6.993 ms 6.905 ms -1.26%
incoming_ref_writes/promotion/10000 67.66 ms 66.77 ms -1.32% 68.15 ms 66.94 ms -1.77%
incoming_ref_writes/staged/1000 2.484 ms 2.542 ms +2.36% 2.474 ms 2.532 ms +2.32%
incoming_ref_writes/staged/10000 26.14 ms 26.59 ms +1.71% 26.19 ms 26.62 ms +1.65%
incoming_ref_writes/wal_recovery/1000 4.059 ms 4.117 ms +1.41% 4.088 ms 4.18 ms +2.25%
incoming_ref_writes/wal_recovery/10000 45.56 ms 46.49 ms +2.05% 45.9 ms 46.83 ms +2.03%
checkpoint/100k 377.8 ms 378.2 ms +0.10% 380.3 ms 380.7 ms +0.09%
checkpoint/10k 28.53 ms 28.62 ms +0.30% 28.66 ms 28.7 ms +0.12%
checkpoint/1k 2.843 ms 2.765 ms -2.74% 2.774 ms 2.77 ms -0.15%
checkpoint/1m 5.126 s 5.079 s -0.92% 5.071 s 5.103 s +0.63%
checkpoint/after_100k_facts/100k 1.461 s 1.459 s -0.14% 1.47 s 1.481 s +0.78%
checkpoint/after_100k_facts/10k 1.41 s 1.403 s -0.44% 1.421 s 1.41 s -0.78%
checkpoint/after_1_fact/100k 504 µs 504.1 µs +0.02% 505.3 µs 512.8 µs +1.48%
checkpoint/after_1_fact/10k 472.3 µs 464.1 µs -1.73% 466.4 µs 467.8 µs +0.30%
checkpoint/after_1_fact/1m 531.5 µs 526 µs -1.04% 532.7 µs 534.2 µs +0.27%
checkpoint/set_storage/inline_unique/10k 38.88 ms 38.82 ms -0.15% 39.1 ms 38.79 ms -0.80%
checkpoint/set_storage/long_repeated/10k 93.61 ms 93.17 ms -0.47% 93.03 ms 93.9 ms +0.94%
checkpoint/set_storage/long_unique/10k 112.8 ms 112.1 ms -0.63% 112.2 ms 112.3 ms +0.02%
checkpoint/storage_v3/multivalue_inline_unique/10k 27.1 ms 26.84 ms -0.97% 27.29 ms 26.91 ms -1.39%
checkpoint/storage_v3/multivalue_long_repeated/10k 38.34 ms 37.88 ms -1.20% 38.24 ms 38.24 ms -0.01%
checkpoint/storage_v3/multivalue_long_unique/10k 58.82 ms 58.12 ms -1.19% 58.45 ms 58.45 ms +0.01%
checkpoint/storage_v3/rebuild_damaged_avet/100k_history 510.3 ms 509.3 ms -0.20% 512.2 ms 513.9 ms +0.33%
checkpoint/storage_v3/verify/100k_history 254.8 ms 251.6 ms -1.23% 254.5 ms 253.7 ms -0.34%
insert/batch_100/100k 455.1 µs 463.4 µs +1.81% 455.5 µs 462.5 µs +1.53%
insert/batch_100/10k 412.8 µs 409.7 µs -0.77% 413.6 µs 417.5 µs +0.94%
insert/batch_100/1k 395.4 µs 397.1 µs +0.45% 402.7 µs 400.7 µs -0.49%
insert/batch_100/1m 410.7 µs 409.6 µs -0.27% 414.8 µs 413.8 µs -0.24%
insert/explicit_tx/100k 5.619 µs 5.654 µs +0.63% 5.603 µs 5.66 µs +1.01%
insert/explicit_tx/10k 4.922 µs 5.119 µs +4.01% 4.973 µs 5.166 µs +3.88%
insert/explicit_tx/1k 4.914 µs 5.058 µs +2.93% 4.942 µs 5.114 µs +3.47%
insert/explicit_tx/1m 4.861 µs 5.044 µs +3.77% 4.905 µs 5.1 µs +3.98%
insert/single_fact/100k 5.019 µs 4.983 µs -0.71% 4.941 µs 4.995 µs +1.10%
insert/single_fact/10k 4.473 µs 4.52 µs +1.05% 4.516 µs 4.552 µs +0.79%
insert/single_fact/1k 4.374 µs 4.409 µs +0.81% 4.37 µs 4.353 µs -0.37%
insert/single_fact/1m 4.243 µs 4.35 µs +2.52% 4.34 µs 4.427 µs +2.02%
insert_file/batch_100/100k 430.2 µs 428.2 µs -0.45% 429.8 µs 426.9 µs -0.69%
insert_file/batch_100/10k 423.5 µs 424.5 µs +0.24% 427.3 µs 424.7 µs -0.60%
insert_file/batch_100/1k 423.3 µs 424.8 µs +0.35% 424.6 µs 428.7 µs +0.97%
insert_file/batch_100/1m 442.5 µs 427.4 µs -3.42% 427.5 µs 426.7 µs -0.18%
insert_file/chunked/execute/65535 305.4 ms 307.1 ms +0.55% 306.2 ms 305.5 ms -0.24%
insert_file/chunked/execute/65537 343.4 ms 339.9 ms -1.01% 336.3 ms 341.9 ms +1.66%
insert_file/chunked/retract/65535 268.4 ms 271.3 ms +1.09% 267.1 ms 270.8 ms +1.37%
insert_file/chunked/retract/65537 542.3 ms 538.5 ms -0.70% 535.7 ms 544 ms +1.54%
insert_file/chunked/statement_rollback/65537 350.4 ms 353.5 ms +0.90% 348.9 ms 356.9 ms +2.30%
insert_file/chunked/write_tx/65535 346.6 ms 345.9 ms -0.20% 339.1 ms 348.5 ms +2.75%
insert_file/chunked/write_tx/65537 469 ms 473.6 ms +0.97% 473.6 ms 464 ms -2.04%
insert_file/explicit_tx/100k 7.34 µs 7.27 µs -0.96% 7.081 µs 7.167 µs +1.21%
insert_file/explicit_tx/10k 7.347 µs 7.238 µs -1.48% 7.112 µs 7.156 µs +0.62%
insert_file/explicit_tx/1k 7.385 µs 7.232 µs -2.07% 7.114 µs 7.146 µs +0.45%
insert_file/explicit_tx/1m 7.22 µs 7.26 µs +0.56% 7.075 µs 7.189 µs +1.62%
insert_file/set_storage/inline_unique/10k 68.58 ms 69.13 ms +0.81% 68.78 ms 69.44 ms +0.96%
insert_file/set_storage/long_repeated/10k 251.6 ms 254.5 ms +1.15% 251.5 ms 252.9 ms +0.57%
insert_file/set_storage/long_unique/10k 252.8 ms 254.1 ms +0.53% 252.7 ms 253.9 ms +0.48%
insert_file/set_storage/scalar/10k 39.51 ms 39.98 ms +1.20% 39.33 ms 40.43 ms +2.80%
insert_file/single_fact/100k 6.301 µs 6.364 µs +1.00% 6.219 µs 6.341 µs +1.96%
insert_file/single_fact/10k 6.367 µs 6.505 µs +2.17% 6.376 µs 6.462 µs +1.35%
insert_file/single_fact/1k 6.417 µs 6.459 µs +0.66% 6.403 µs 6.5 µs +1.51%
insert_file/single_fact/1m 6.293 µs 6.384 µs +1.46% 6.272 µs 6.367 µs +1.52%
open/wal_replay/100k 300.9 ms 301.9 ms +0.33% 300 ms 302.6 ms +0.89%
open/wal_replay/10k 33.41 µs 32.85 µs -1.68% 34.44 µs 31.88 µs -7.45%
open/wal_replay/1k 28.89 µs 27.87 µs -3.51% 29.19 µs 28.44 µs -2.58%

Checklist

  • cargo test passes (2,190 passed, 0 failed, 23 ignored; with test-hooks 2,228 passed, 32 ignored)
  • cargo clippy -- -D warnings is clean (native with and without test-hooks, browser wasm, wasip1)
  • cargo fmt --check passes
  • New code has tests (unit and/or integration)
  • Error paths are tested, not just happy paths
  • No unwrap() / expect() in library code paths
  • CHANGELOG.md updated under Unreleased
  • I have read PHILOSOPHY.md and this change aligns with it

Notes for reviewer

  • Records exhaustion can be reported before links exhaustion, because liveness is established only after every layer's range has been read.
  • If the promotion to a large transaction fails, the staged facts are kept so a later lookup in the same transaction still sees every completed statement; commit is refused with STG-046.
  • After a failed statement finalization in a large transaction, the lookup keeps the completed statements' roots; their pages stay held until the transaction ends.
  • Also run: WASI tests (1,232 passed, 7 ignored) and headless Firefox browser tests. These and the size and benchmark figures predate the later test-only commits; no production source changed since.

🤖 Generated with Claude Code

https://claude.ai/code/session_01H2a7QmsdjnGhRdBSbw6GB7

adityamukho and others added 3 commits November 28, 2026 10:48
…#924)

WriteTransaction and OwnedWriteTransaction gain incoming_refs, which
returns every live scalar reference to an entity, ignoring valid time, or
an explicit exhausted outcome when a links or records budget is exceeded.
Pending and staged facts keep target-keyed positions, and durable and
large-transaction data are walked by VAET prefix, so the work depends only
on the target's own history.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H2a7QmsdjnGhRdBSbw6GB7
@codecov
codecov Bot commented Nov 28, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.02233% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/db.rs 95.00% 3 Missing and 1 partial ⚠️
src/incoming.rs 97.03% 2 Missing and 2 partials ⚠️
src/graph/storage.rs 97.53% 2 Missing ⚠️
src/storage/reader.rs 97.22% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

adityamukho and others added 2 commits November 28, 2026 18:13
…ked files portably (#924)

Exercise the default CommittedReader method, which no test executed and
which left src/storage/mod.rs below its coverage floor. Windows file locks
are mandatory, so the incoming-reference tests compare the open database's
length there and its exact bytes elsewhere.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H2a7QmsdjnGhRdBSbw6GB7
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.

1 participant

0