Skip to content

perf(storage): O(1) storage_tail append via newest-first batch list - #38

Merged
tiensonqin merged 1 commit into
mainfrom
devin/storage-tail-gc
Oct 5, 2026
Merged

tiensonqin merged 1 commit into
mainfrom
devin/storage-tail-gc

Conversation

@tiensonqin

@tiensonqin tiensonqin commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Conn.transact/apply_report did conn.storage_tail @ [report.tx_data] on every transaction — O(#batches) per tx. conn.storage_tail now keeps per-transaction datom list batches newest-first and conses report.tx_data; List.rev restores forward (tx, then in-tx) order only where the flat tail is consumed: store_tail writes, the Conn.storage_tail accessor, and make/restore_conn seeding. The persisted Storage_tail payload at address "1" is order-identical to before.

Two count-side improvements ride along:

  • Storage.tail_datom_count folds group lengths (fold_left over List.length) instead of List.concat |> List.length, so the compaction check no longer allocates a flat copy of the tail.
  • persist_transact_tail (the db-level transact path) computes tail_datom_count groups + length tx_data before materializing groups @ [tx_data], so a compaction-triggering tx skips the append entirely.

No signature or on-disk format changes. The auto-GC work originally in this PR moved to #40.

Tests

All 34 native test suites pass. New regression tests in test_storage.ml:

  • test_conn_tail_write_order — stored Storage_tail groups stay in tx order then in-tx order across multiple txs, a restore_conn (which exercises the reversed internal repr), a compaction, and the next tx; Conn.storage_tail returns the same forward order
  • test_tail_datom_count — grouped-tail count including an empty group

Link to Devin session: https://app.devin.ai/sessions/eb0e07b23c794857b6836d8a143d1688
Open in Devin Desktop: https://app.devin.ai/desktop/session/eb0e07b23c794857b6836d8a143d1688?variant=devin
Requested by: @tiensonqin

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

conn.storage_tail now keeps per-transaction datom batches newest-first
and conses each report's tx_data, replacing the O(#batches) list append
on every transaction. The forward (tx, then in-tx) order is restored
with List.rev only where the flat tail is consumed: store_tail writes,
the Conn.storage_tail accessor, and restore seeding — so the persisted
Storage_tail payload is order-identical to before.

Storage.tail_datom_count folds group lengths instead of concat |> length,
and persist_transact_tail (the db-level transact path) computes the
compaction count before materializing groups @ [tx_data], so a
compaction-triggering tx skips the append entirely.

Regression coverage in test_storage: on-disk Storage_tail group order
across transacts, restore_conn, and compaction; Conn.storage_tail
accessor order; tail_datom_count over grouped tails.
@devin-ai-integration devin-ai-integration Bot changed the title perf(storage): O(1) storage_tail append + opt-in auto-GC after compaction perf(storage): O(1) storage_tail append via newest-first batch list Oct 5, 2026
@tiensonqin
tiensonqin merged commit e8b517e into main Oct 5, 2026
1 check passed
@tiensonqin
tiensonqin deleted the devin/storage-tail-gc branch October 5, 2026 07:32
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