Repository navigation
BracketGallop: return the hint after two comparisons when it is the answer - #119
Merged
ChrisRackauckas merged 2 commits intoOct 1, 2026
Merged
Conversation
…nswer A warm-started caller (an interpolation interval lookup feeding each answer back as the next hint) hits its hint most of the time, and the two comparisons `v[hint] ≤ x < v[hint + 1]` already decide the result. The hinted bracket-gallop kernels found that width-one bracket and then still ran the bounded bisection over it, two more comparisons and loads per query. Both polarities now return early on a hit; an equal neighbour fails the second test so duplicates still go through the bisection. On a 1e5-knot vector with a correlated query walk (83 % hint hits) the hinted search goes from 6.3 to 4.7 ns per query on the CPU, and 3.3 ns with `order = Base.Order.Lt(<)`, against 3.1 ns for a hand-written interval search; in a KernelAbstractions kernel on an RTX 4080 SUPER the launch goes from 4.0 to 2.7 ms against 2.2 ms. Cold and miss paths are unchanged. Adds a randomized test set over hints in and out of range, duplicates and reverse ordering, a `warm_walk` benchmark cell, and a docstring note on the hit path and the `isless` cost. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The hit check and the bracket expansion were two stages: on a miss the expansion re-read the hint's neighbours and then handed a bracket to Base's bounded bisection, which widens it by one on each side and knows nothing about either end. The hinted kernels are now one pass: the two comparisons at the hint decide a hit, and otherwise the gallop starts from the side they established, doubling its step until it brackets the answer; a bisection that knows one end of the bracket is a valid candidate finishes. `bracketstrictlymonotonic` and its `_first` twin stay defined (the QA suite checks them) but the kernels no longer call them. Same correlated walk as the previous commit, RTX 4080 SUPER: 2.7 → 1.9 ms per launch with the default ordering, now ahead of the hand-written interval search (2.2 ms); CPU 4.7 → 3.6 ns per query, 2.4 ns with `order = Base.Order.Lt(<)`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
ChrisRackauckas
referenced
this pull request
Oct 13, 2026
Agent-Harness: Devin CLI 3000.11.3 Agent-Model: Fusion (Claude Opus 5.5 Medium + SWE-2 Medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/flash-hour.json Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.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.
What
The hinted
BracketGallopkernels (_kernel_last_bracket_gallop/_kernel_first_bracket_gallop) are now a single pass:v[hint] ≤ x < v[hint + 1](searchsorted_last) orv[hint - 1] < x ≤ v[hint](searchsorted_first), and the hint is returned. Previouslybracketstrictlymonotonicfound that width-one bracket after the same two comparisons and then still ran the bounded bisection over it.Duplicates are handled by the predicates:
searchsorted_lastasks for the lastv[i] ≤ x, so an equal right neighbour is not a hit and the gallop moves on; likewise an earlier duplicate forsearchsorted_first. Out-of-range hints fall back to the plain bisection as before. Results are unchanged.bracketstrictlymonotonicand its_firsttwin stay defined (the QA suite checks them) but the kernels no longer call them; happy to delete them if preferred.This is the pattern of a warm-started interval lookup (an interpolation evaluated at slowly moving times, each answer fed back as the next hint): the hint is the answer most of the time and, when it is not, the answer is a few intervals away.
Also in this PR:
Int32hint);warm_walkcell inbenchmark/benchmarks.jl(hint carried from the previous answer);islessordering for float vectors (order = Base.Order.Lt(<)skips the NaN and signed-zero handling when the vector has no NaN).Measurements
Correlated query walk over a 1e5-knot sorted
Float64vector, 83 % of queries land in the hint's interval. "Hand-written" is a minimal warm-started interval search (gallop from the hint, closed-bracket bisection, plain<) used as the reference; the FFF result is clamped to the interval range so the two are bit-identical (checked on 90 000 randomized cases and on every query of the walks below).CPU, ns per query (single thread):
Lt(<)GPU, ms per launch of 67 M queries in a KernelAbstractions kernel (each thread walks its own sequence, hint carried in a register), minimum of 15 launches:
Lt(<)Cold (no hint) and out-of-range paths are unchanged. An intermediate version with only the hit path (first commit) regressed on the H100 with the default ordering; the fused miss path (second commit) removed that.
Tests
GROUP=Core(251 683 tests) andGROUP=QApass locally.🤖 Generated with Claude Code · model: claude-fable-5-1
Review: skimmed