Speed up hot SurfTrackerData accessors (bit-identical)#1083
Open
robert-kofler42 wants to merge 1 commit into
Open
Speed up hot SurfTrackerData accessors (bit-identical)#1083robert-kofler42 wants to merge 1 commit into
robert-kofler42 wants to merge 1 commit into
Conversation
valid_int / lookup_int / lookup_int_loc / surfsC are called in the surface
tracer's inner loop (the unwrapping hot path). Each did redundant work:
- valid_int called sm->rawPoints() six times, lookup_int / lookup_int_loc
three times each. rawPoints() is a virtual call that returns a cv::Mat
header by value (atomic refcount increment/decrement on the shared pixel
data) — so each call was a virtual dispatch plus two atomic ops. Bind it
once into a local const cv::Mat_<cv::Vec3f> and reuse.
- lookup_int / valid_int did _data.contains(id) followed by loc(sm,p) (which
is _data[{sm,p}]) — two hash lookups of a non-trivial pair key. surfsC did
_surfs.contains(loc) + _surfs.find(loc). Replace each with a single find().
No numeric change: same values, same control flow (contains() already proved
the key present, so operator[] never inserted). Verified bit-identical by an
output checksum over a synthetic SurfTrackerData/QuadSurface sweep (identical
before/after) and the existing test_surf_tracker_data / merge tests pass.
Microbench (valid_int + lookup_int over a 150x150 grid, 40 sweeps, median):
163 ns/cell -> 66 ns/cell, ~2.5x faster on the accessor pair.
|
Someone is attempting to deploy a commit to the scroll Team on Vercel. A member of the Team first needs to authorize it. |
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
valid_int,lookup_int,lookup_int_locandsurfsCinSurfTrackerDataare called in the surface tracer's inner loop — the unwrapping hot path (the master plan's #1 bottleneck). Each did redundant work:sm->rawPoints()called repeatedly — 6× invalid_int, 3× each inlookup_int/lookup_int_loc.rawPoints()is a virtual call that returns acv::Matheader by value, i.e. an atomic refcount increment/decrement on the shared pixel data. So every use was a virtual dispatch + two atomic ops. Now bound once into a localconst cv::Mat_<cv::Vec3f>and reused.lookup_int/valid_intdid_data.contains(id)thenloc(sm,p)(which is_data[{sm,p}]), two lookups of a non-trivial pair key;surfsCdidcontains()+find(). Each is now a singlefind().Correctness — bit-identical
Same values, same control flow (
contains()had already proved the key present, so the oldoperator[]never inserted). Verified by an output checksum over a syntheticSurfTrackerData/QuadSurfacesweep — identical before/after — and the existingtest_surf_tracker_dataand merge tests pass.Performance
Microbench (
valid_int+lookup_intover a 150×150 entry grid, 40 sweeps, median of 7,-O3):~2.5× faster on the accessor pair. These run per traced point, so the win lands directly on the segmentation/unwrapping inner loop. Bit-identical, no numeric change. Applies cleanly on
main.🤖 Generated with Claude Code