Skip to content

perf: make provenance/alias walks and multi-sort index-driven#1

Merged
LZL0 merged 3 commits into
masterfrom
perf/index-driven-graph-ops
Jun 22, 2026
Merged

perf: make provenance/alias walks and multi-sort index-driven#1
LZL0 merged 3 commits into
masterfrom
perf/index-driven-graph-ops

Conversation

@LZL0

@LZL0 LZL0 commented Jun 22, 2026

Copy link
Copy Markdown
Member

Measured impact (python benchmarks/perf.py)

Naive time ~quadruples per doubling (quadratic); optimized ~doubles (linear):

op (n=1600) naive optimized speedup
cascade_retract (chain) 123 ms 2.4 ms 51×
get_alias_group (chain) 176 ms 0.5 ms 355×
get_dependents(transitive) 106 ms 0.85 ms 125×
multi-sort (n=8000) 26 ms 5.2 ms

The multi-sort win applies to every sorted query (it also dropped the test-suite runtime from ~1.6s to ~0.45s).


Summary by cubic

Made provenance and alias traversals and multi-sort index-driven to remove repeated full scans and per-node re-clones. This turns several quadratic paths into ~linear with up to 355× speedups while preserving behavior and event ordering. Added a full API.md reference and linked it from README.md.

  • Refactors

    • Added build_children_index and used it in cascade_retract, get_dependents(transitive), and export_slice to traverse once instead of rescanning.
    • Rewrote cascade_retract to retract in a single pass (clone items once, lazy reverse-edge index) using post-order DFS; emits identical events and removes incident edges once.
    • Replaced cmp_to_key comparator with a tuple-key multi-sort for numeric fields; keeps stable ordering and speeds up all sorted queries.
    • Built one-shot ALIAS adjacency for get_alias_group and export_slice (both directions) to avoid per-node edge scans while keeping traversal order.
  • New Features

    • Added API.md full API reference and linked it from README.md.
    • Added micro-benchmarks and equivalence tests to validate behavior and measure speedups.

Written for commit 863e587. Summary will update on new commits.

Review in cubic

Replace repeated full-scan loops and per-command re-clones with one-shot
indexes, turning several O(n^2) graph operations into roughly O(n) while
keeping behavior (results, ordering, and emitted event sequences) identical.

- query: tuple-key _multi_sort (numeric fields) replaces cmp_to_key (~4-5x
  faster, byte-identical ordering incl. stable tie-breaks); add shared
  build_children_index helper.
- integrity: cascade_retract now walks the children index and retracts in a
  single pass (clone items once, lazy reverse edge index) instead of one
  apply_command per node; get_dependents(transitive) and get_alias_group use
  one-shot indexes.
- transplant: export_slice include_children/include_aliases walk one-shot
  indexes.

Add tests/test_perf_equivalence.py pinning the optimized paths against inline
pre-optimization references (notably byte-identical cascade event sequences),
and benchmarks/perf.py contrasting naive vs optimized scaling.

Measured (n=1600): cascade_retract 51x, get_alias_group 355x,
get_dependents(transitive) 125x; multi-sort 5x at n=8000.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

You’re at about 94% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Re-trigger cubic

@LZL0
LZL0 merged commit 23d34fc into master Jun 22, 2026
5 checks passed
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