8000 perf(storage): clone pending facts straight into all_facts (#543) by adityamukho · Pull Request #587 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

perf(storage): clone pending facts straight into all_facts (#543) - #587

Merged
adityamukho merged 1 commit into
v3from
perf/543-all-facts-copy
Oct 14, 2026
Merged

adityamukho merged 1 commit into
v3from
perf/543-all-facts-copy

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Fixes a regression from #580 (unreleased, v3 only). Refs #543.

Snapshot::all_facts built its pending part with pending_range, which cloned the pending facts into a temporary vector before they were moved into the result. Recursive rules read every fact of their in-memory derived store, which holds the whole database as pending facts, so each read did an extra allocation and copy of the full set. The perf envelope's recursive_ancestors at 1M facts went up 24%.

all_facts now starts from the committed facts' vector and clones the pending facts onto its end under the pending lock. pending_range (used by FactLog) shares the same helper and keeps its clamping. Ordering and locking are unchanged.

Measurements

recursive_ancestors, 1M-fact envelope fixture, envelope profile, 10 runs per sample, median. Run on an idle machine, with each pair run in parallel and then repeated with the sides swapped.

Build Run 1 Run 2 (swapped)
base before #580 (27951e3) 45.9 s 45.4 s
v3 (771fe4e) 56.4 s 56.1 s
this PR 45.0 s / 45.0 s 45.1 s / 45.4 s

The PR's two numbers per run are its two pairings, one against base and one against v3.

A profile of v3 showed a to_vec frame at 3.6% that base does not have. hot_current and hot_as_of were re-measured the same way and show no regression from #580; the +12% in the earlier envelope run was noise.

Tests

cargo test: 1463 passed, 10 ignored. No new test, because behaviour is unchanged: the existing snapshot and fact-log tests cover the ordering and the clamping.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HyLscCUuJ1GQpdAeX79EdR

Snapshot::all_facts collected the pending facts with pending_range, which
copied them into a temporary vector before moving them into the result.
Recursive rules read every fact of an in-memory store holding the whole
database as pending facts, so each read allocated and copied it twice:
recursive_ancestors at 1M facts went from 45.9 s to 56.4 s (+24%) after
#580. The pending facts are now cloned onto the committed facts' vector.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HyLscCUuJ1GQpdAeX79EdR
@codecov
codecov Bot commented Oct 14, 2026
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adityamukho
adityamukho merged commit e2bddeb into v3 Oct 14, 2026
24 checks passed
@adityamukho
adityamukho deleted the perf/543-all-facts-copy branch October 14, 2026 07:38
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