Add PathQuery — reusable buffer-recycling path queries - #1
Merged
Conversation
…for repeated queries)
Shows the reuse benefit is size-dependent: at 4096 nodes PathQuery (~50.2ms) is only marginally ahead of one-shot node_path (~50.5ms) and both sit ~3% behind amortized C++ (~48.9ms). The path-query bottleneck is the shortcut unpack path, not per-call allocation.
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.
Summary
Adds
cch::PathQuery— a reusable, buffer-recycling node-path query (the path-query analogue of the existingElimTreeQueryfor distances). It allocates its scratch buffers and computes the inverse-rankorderonce innew(), then answers each.path(metric, source, target)reusing them with a cheap touched-only reset, instead of the freenode_pathfn's per-call allocation + O(n)orderrebuild.Correctness
node_pathand the C++ oracle. The 200-pair LCG differential is run through a single reusedPathQuery(proving the reset restores state across queries), plus interleaved/repeated/self-pair tests vs a freshnode_path.get_uncheckedon the data-dependent distance/pred accesses, made sound by a one-timeup_head < node_countvalidation innew()(hardassert!+# Panicsdoc + a#[should_panic]test) — mirroringElimTreeQuery.node_pathis unchanged (purely additive diff; its 200-pair gate intact). 100% line coverage held; clippy-D warnings+ fmt clean.Performance — honest assessment
node_pathone-shotPathQueryreusedPathQuery is at parity with C++, not a clear win. Two honest takeaways from the benches:
orderrebuild compounds).unpack_arc's merge-join +find_up_arc), which still has per-access bounds checks — a separate optimization, not addressed here.Why merge it anyway
It's the correct reuse API for repeated path queries (consistent with
ElimTreeQuery), it's sound + fully tested, and the per-call-allocation savings grow with graph size. It does not regressnode_path.What it does NOT do
It is not the lever that pushes path queries clearly past C++ — that's the unpack-path optimization, proposed as a focused follow-up.