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

Merged
LZ
5mo ago
+1581-46

Measured impact (python benchmarks/perf.py)

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

op (n=1600)naiveoptimizedspeedup
cascade_retract (chain)123 ms2.4 ms51×
get_alias_group (chain)176 ms0.5 ms355×
get_dependents(transitive)106 ms0.85 ms125×
multi-sort (n=8000)26 ms5.2 ms5×

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.