DistanceTester: take a direct path for Overlap features (~8% faster TRIBL2/IB1 test)#16
Open
antalvdb wants to merge 1 commit into
Open
DistanceTester: take a direct path for Overlap features (~8% faster TRIBL2/IB1 test)#16antalvdb wants to merge 1 commit into
antalvdb wants to merge 1 commit into
Conversation
The inner distance loop dispatched every feature through a virtual metricTestFunction::test() -> Feature::fvDistance() (which re-checks the storable/numeric branches on every call) -> a virtual metric->distance(), plus a permutation[] indirection -- all to compute, for a plain Overlap feature, just (F == G ? 0 : weight). Precompute once, in permuted order, a flat metricTestFunction array (removing the permutation indirection) and an Overlap flag per feature, and let Overlap features take the direct (F == G ? 0 : weight) path. Other metrics (MVDM, numeric, ...) keep the existing path. Measured (TRIBL2, 20k test instances, reused saved base; deterministic instruction counts, min of 3): 161.30 B -> 155.19 B, i.e. about -8% of the test phase. Only IB1/TRIBL2 use DistanceTester (IGTree computes no distances). Output is byte-identical, including with +v db (which depends on the exact distances and neighbour ordering). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
The inner distance loop in
DistanceTester::test()dispatched every feature through a virtualmetricTestFunction::test()→Feature::fvDistance()(which re-checks the storable / numeric branches on every call) → a virtualmetric->distance(), plus apermutation[]indirection — all to compute, for a plain Overlap feature, just(F == G ? 0 : weight).This precomputes once, in permuted order, a flat
metricTestFunctionarray (removing thepermutation[]indirection) and an Overlap flag per feature, and lets Overlap features take the direct(F == G ? 0 : weight)path. Other metrics (MVDM, numeric, …) keep the existing path unchanged.Measured impact
TRIBL2, 20k test instances written to /dev/null, reused saved instance base; deterministic instruction counts, min of 3 (the base load is identical before/after, so the delta is the test phase):
≈ −8% of the test phase. Only IB1 and TRIBL2 use
DistanceTester(IGTree computes no distances, so it is unaffected); IB1 — being all-distance — likely benefits more.Correctness
Output is byte-identical, including with
+v db(distributions printed), which depends on the exact distances and neighbour ordering. Verified on TRIBL2 (20k), plain and+v db.Posting for your consideration — happy to adjust.
🤖 Generated with Claude Code