perf: make provenance/alias walks and multi-sort index-driven#1
Merged
Conversation
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.
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measured impact (
python benchmarks/perf.py)Naive time ~quadruples per doubling (quadratic); optimized ~doubles (linear):
cascade_retract(chain)get_alias_group(chain)get_dependents(transitive)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.mdreference and linked it fromREADME.md.Refactors
build_children_indexand used it incascade_retract,get_dependents(transitive), andexport_sliceto traverse once instead of rescanning.cascade_retractto retract in a single pass (clone items once, lazy reverse-edge index) using post-order DFS; emits identical events and removes incident edges once.cmp_to_keycomparator with a tuple-key multi-sort for numeric fields; keeps stable ordering and speeds up all sorted queries.get_alias_groupandexport_slice(both directions) to avoid per-node edge scans while keeping traversal order.New Features
API.mdfull API reference and linked it fromREADME.md.Written for commit 863e587. Summary will update on new commits.