Skip to content

ENH: benchmark the in-memory lookups on hot paths - #782

Merged
d-chambers merged 1 commit into
devfrom
micro-benchmarks
Jul 26, 2026
Merged

ENH: benchmark the in-memory lookups on hot paths#782
d-chambers merged 1 commit into
devfrom
micro-benchmarks

Conversation

@d-chambers

@d-chambers d-chambers commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Description

Adds micro-benchmarks for the in-memory lookups DASCore repeats on its hot paths.

The existing benchmarks are all end-to-end and disk-bound, which makes them blind at this scale. A concrete example from the free-threading series: replacing the memo on _materialize_remote_file with locking alone made resolving an already-cached remote file 12.2 µs → 35.1 µs, a 2.9x regression on every remote file open. In test_scan, which opens about 40 files, that is roughly 1 ms on a 240 ms benchmark — 0.4%, comfortably inside run-to-run noise. It was found by hand, and only because someone asked the right question.

Three regressions in that series had the same shape (a cache removed in favor of a lock), and none of them were visible to CI.

What is added

benchmarks/test_lookup_benchmarks.py, covering the lookups those paths make:

  • Format resolution once every plugin is loaded: the repeat load_plugins() no-op, resolution by extension, and resolution by known format/version.
  • Remote cache: resolving a remote file which is already downloaded (uses the in-memory filesystem, so no network).
  • IO resources: repeat handle lookup inside one operation, and ensure_local_file on a path which is already local.
  • Spool access: repeat indexing and repeat length on an in-memory spool.

Each repeats its lookup enough times to do a few milliseconds of work, so the measurement is not dominated by setup. The counts differ per benchmark because the operations differ in cost by two orders of magnitude — from about 0.05 µs for the load_plugins no-op to about 13 µs for the remote-cache resolution.

Do they actually resolve changes at this scale?

Yes — checked against a change already merged. Running this file at 1183dbcc (before #779) and at current dev:

benchmark before #779 current dev
test_load_plugins_already_loaded 0.02 s below the 0.005 s floor
test_yield_fiberio_by_format 0.02 s 0.01 s

Those match the 4x and 1.3x improvements measured by hand when #779 landed. CodSpeed counts instructions rather than wall time, so its resolution is better still.

Notes

  • Nothing outside benchmarks/ changes.
  • Add the benchmark label to run CodSpeed on a PR; that gate is unchanged.
  • The remote-cache fixture sets configuration with the permanent set_config tier, matching the existing convention for class- and module-scoped benchmark fixtures.

Changelog

none

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes.
  • documented the new feature with docstrings and/or appropriate doc page.
  • included tests. See testing guidelines.
  • added the "ready_for_review" tag once the PR is ready to be reviewed.

The existing benchmarks are end-to-end and disk-bound, so a change worth
microseconds per lookup disappears into their noise: a regression that
made resolving an already-cached remote file 12us slower moved test_scan
by about 0.4%, well inside run-to-run variation.

Adds small in-memory benchmarks for the lookups those paths repeat:
format resolution once plugins are loaded, resolving a cached remote
file, IO handle lookup within one operation, and repeat spool access.
Each repeats enough times to do a few milliseconds of work.

They resolve changes at the intended scale: across the registry
synchronization in #779, test_load_plugins_already_loaded moves from
0.02s to under the 0.005s reporting floor.
@d-chambers d-chambers added ready_for_review PR is ready for review benchmark Run the benchmark suite labels Jul 25, 2026
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@d-chambers, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 63e29747-ead2-4ca5-b718-770abb82c88a

📥 Commits

Reviewing files that changed from the base of the PR and between d4a21fc and a05c53f.

📒 Files selected for processing (2)
  • benchmarks/readme.md
  • benchmarks/test_lookup_benchmarks.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch micro-benchmarks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d4a21fc) to head (a05c53f).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #782   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          164       164           
  Lines        17589     17589           
=========================================
  Hits         17589     17589           
Flag Coverage Δ
network 48.31% <ø> (ø)
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq

codspeed-hq Bot commented Jul 25, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 65 untouched benchmarks
🆕 8 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_load_plugins_already_loaded N/A 42.3 ms N/A
🆕 test_yield_fiberio_by_extension N/A 86.5 ms N/A
🆕 test_yield_fiberio_by_format N/A 100.7 ms N/A
🆕 test_ensure_local_file_for_local_path N/A 64.4 ms N/A
🆕 test_repeat_get_resource N/A 53.7 ms N/A
🆕 test_ensure_local_file_already_cached N/A 67.4 ms N/A
🆕 test_repeat_len N/A 172.4 ms N/A
🆕 test_repeat_patch_access N/A 82 ms N/A

Comparing micro-benchmarks (a05c53f) with dev (d4a21fc)

Open in CodSpeed

@d-chambers
d-chambers merged commit 9b3055f into dev Jul 26, 2026
30 checks passed
@d-chambers
d-chambers deleted the micro-benchmarks branch July 26, 2026 04:15
@d-chambers d-chambers removed the ready_for_review PR is ready for review label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

benchmark Run the benchmark suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant