Skip to content

[Perf] Cache last-call result in perf_dispatch for single-compatible case#438

Merged
hughperkins merged 3 commits intomainfrom
hp/perf-dispatch-cache-last-call
Mar 31, 2026
Merged

[Perf] Cache last-call result in perf_dispatch for single-compatible case#438
hughperkins merged 3 commits intomainfrom
hp/perf-dispatch-cache-last-call

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

When only one registered implementation is compatible for a given geometry, cache the args/kwargs/impl from the last call. On subsequent calls with the same objects (identity check via is), return the cached impl directly, bypassing geometry hash computation, dict lookups, and time.time() checks.

Only activates for the single-compatible path; multi-compatible benchmarking with repeat_after_seconds is unaffected.

Reduces perf_dispatch overhead from ~9.5 us to ~1.8 us per call, closing the ~13% FPS gap on CPU benchmarks (e.g. franka_random) to ~1.8%.

Issue: #

Brief Summary

copilot:summary

Walkthrough

copilot:walkthrough

Comment thread python/quadrants/lang/_perf_dispatch.py Outdated
if self._forced_impl is not None:
return self._forced_impl(*args, **kwargs)

cached = self._cached_impl
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use in the if directly

Comment thread python/quadrants/lang/_perf_dispatch.py Outdated
@hughperkins hughperkins force-pushed the hp/perf-dispatch-cache-last-call branch from c9fef35 to 227c73d Compare March 31, 2026 02:46
…case

When only one registered implementation is compatible for a given
geometry, cache the args/kwargs/impl from the last call. On subsequent
calls with the same objects (identity check via `is`), return the
cached impl directly, bypassing geometry hash computation, dict
lookups, and time.time() checks.

Only activates for the single-compatible path; multi-compatible
benchmarking with repeat_after_seconds is unaffected.

Reduces perf_dispatch overhead from ~9.5 us to ~1.8 us per call,
closing the ~13% FPS gap on CPU benchmarks (e.g. franka_random)
to ~1.8%.
@hughperkins hughperkins force-pushed the hp/perf-dispatch-cache-last-call branch from 227c73d to 37e394a Compare March 31, 2026 02:46
@hughperkins
Copy link
Copy Markdown
Collaborator Author

I have read every line added in this PR, and reviewed the lines. I take responsibilty for the lines added and removed in this PR, and won't blame any issues on Opus.

Comment thread python/quadrants/lang/_perf_dispatch.py Outdated
return self._forced_impl(*args, **kwargs)

if self._cached_impl is not None:
ca = self._cached_args
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we put ca, ck assign on same line?

@hughperkins hughperkins force-pushed the hp/perf-dispatch-cache-last-call branch from 86b1fbb to e01db70 Compare March 31, 2026 09:50
@hughperkins hughperkins enabled auto-merge (squash) March 31, 2026 09:50
@hughperkins hughperkins merged commit 4a73a2e into main Mar 31, 2026
46 checks passed
@hughperkins hughperkins deleted the hp/perf-dispatch-cache-last-call branch March 31, 2026 10:37
hughperkins added a commit that referenced this pull request Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants