perf: memoize k×s segment-id construction#364
Merged
Conversation
The segment ids are static per (grid, s) pair but the partial pre-bin runs once per likelihood evaluation in a fit, and the per-pixel construction loop cost ~60 ms on a realistic 3000-pixel adaptive mask — per evaluation. An lru_cache on the sizes' bytes makes repeat calls ~80 us (x750). The returned array is marked read-only (shared across callers); the divisibility guard fires identically through the cache. Co-Authored-By: Claude Fable 5 <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.
Follow-up to the k×s coupling (#362): the design promised the segment map cached; phase 2 rebuilt it per call — a per-likelihood-evaluation cost in fits.
lru_cacheon the sizes' bytes: first call 62 ms on a realistic 3000-pixel adaptive mask, cached calls 83 µs (×750), returned array read-only, guard behaviour identical. Suite: 863 passed, zero test edits (behaviour-preserving).🤖 Generated with Claude Code