Skip to content

perf(merge): pre-index base facts for O(1) lookup in collaborate (SCALE-P2-4 / #46) - #68

Merged
CryptoJones merged 1 commit into
mainfrom
perf/collaborate-fact-index
Sep 15, 2026
Merged

CryptoJones merged 1 commit into
mainfrom
perf/collaborate-fact-index

Conversation

@CryptoJones

Copy link
Copy Markdown
Owner

Description

Resolves #46 (SCALE-P2-4 / Codeberg #161).

In scylla_merge::collaborate, matching existing base facts for each incoming fact previously executed base.facts.iter().find(...) inside for fact in &incoming.facts, and post-loop confidence replacement executed base.facts.iter_mut().find(...). For large fact sets, this created quadratic $O(F_{\text{incoming}} \cdot F_{\text{base}})$ scans.

Key Changes

  • Pre-index existing base facts by (StableId, Discriminant<FactKind>) -> usize prior to iterating through incoming facts.
  • Turn both the existing fact check and the post-loop confidence replacement into $O(1)$ lookups, reducing fact merge complexity to $O(F_{\text{incoming}} + F_{\text{base}})$.
  • Added unit test collaborate_handles_many_facts_with_indexed_lookup in crates/scylla-merge/src/lib.rs.
  • Updated BACKLOG.md and ARCHITECTURE_REVIEW.md.
  • Bumped workspace version to 0.7.9 and updated CHANGELOG.md.

Verification Results

  • cargo fmt --all -- --check: Passed
  • cargo clippy --workspace --all-targets -- -D warnings: Passed
  • cargo test --workspace: Passed (all 28 tests in scylla-merge passed, workspace green)
  • cargo audit: Passed (0 vulnerabilities, 6 allowed warnings)
  • ./scripts/check-wasm.sh: Passed
  • node crates/scylla-wasm/web/verify.mjs: Passed (browser round-trip green)

…LE-P2-4 / #46)

- In scylla_merge::collaborate, pre-build HashMap<(StableId, Discriminant<FactKind>), usize> over base.facts
- Replace O(F_incoming * F_base) linear scan with O(1) indexed lookup for existing fact matching and confidence replacement
- Add unit test collaborate_handles_many_facts_with_indexed_lookup verifying correct multi-fact merging and confidence resolution
- Update BACKLOG.md and ARCHITECTURE_REVIEW.md tracking SCALE-P2-4 / #46
- Bump workspace package version to 0.7.9 and record release in CHANGELOG.md
- Verification: cargo fmt, cargo clippy, cargo test, cargo audit, check-wasm.sh, and verify.mjs pass cleanly
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: c64da6d6-7224-4239-87a3-e4915e9f23fa


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@CryptoJones
CryptoJones merged commit 7d908da into main Sep 15, 2026
3 checks passed
@CryptoJones
CryptoJones deleted the perf/collaborate-fact-index branch September 15, 2026 17:51
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.

[SCALE-P2-4] collaborate existing-fact lookup is O(F_incoming · F_base)

1 participant