Skip to content

bench(rwlock): add upgradable lock stage timings - #405

Open
ismaeelakin wants to merge 6 commits into
apache:mainfrom
ismaeelakin:rwlock-stage-measurements
Open

ismaeelakin wants to merge 6 commits into
apache:mainfrom
ismaeelakin:rwlock-stage-measurements

Conversation

@ismaeelakin

@ismaeelakin ismaeelakin commented Nov 3, 2026 •

Copy link
Copy Markdown

What changed

Adds stage timings for the UpgradableRwLock investigation in #404:

  • uncontended acquisition and promotion measured separately
  • acquisition while an ordinary reader is held
  • promotion while 1, 4, or 16 ordinary read guards remain held
  • promotion while a writer is queued behind the existing reservation
  • a later upgradable request queued behind a writer
  • --test support for the repository benchmark smoke run

This PR adds the measurement step requested in #404; it does not change the lock implementation or establish a speedup. Per-operation clock reads add overhead. Reader-promotion timings include dropping the readers and the wake/handoff, and queued acquisition includes the writer's handoff. The benchmark manually polls futures with a non-scheduling waker, so its timings exclude executor scheduling overhead. Treat the results as diagnostics.

Verification

Passed locally on Windows 11 (Intel Core i5-6300U):

  • cargo x test and benchmark runs with stable rustc 1.99.1
  • cargo x lint with nightly rustc 1.101.0
  • cargo x bench -- --test
  • cargo x bench --bench upgradable_stages -- --rounds 1000000 --repeat 5

The local timings and their run-to-run spread are recorded in issue #404.

Refs #404

@orthur2
orthur2 self-requested a review November 7, 2026 07:27
Comment thread benchmarks/Cargo.toml
name = "ecosystem"
path = "benches/ecosystem/main.rs"

[[bench]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cargo x bench -- --list worked before and now fails, because the default run includes this target and it rejects --list. I'd leave it out of the default run and smoke-test it separately in CI.

Comment thread benchmarks/benches/upgradable_stages.rs Outdated
let mut upgrade = pin!(RwLockUpgradableReadGuard::upgrade(guard));
let start = Instant::now();
poll_pending(upgrade.as_mut(), &mut context);
drop(readers);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

drop(readers) also frees the Vec inside the timed window. Reusing one buffer across rounds and calling clear() here avoids that.

Comment on lines +79 to +88
let start = Instant::now();
let guard = poll_ready(lock.upgradable_read(), &mut context);
acquisition += start.elapsed();

let start = Instant::now();
let writer = poll_ready(RwLockUpgradableReadGuard::upgrade(guard), &mut context);
promotion += start.elapsed();

black_box(*writer);
drop(writer);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An empty timed interval costs about 15 ns on my M5, roughly half the reported acquisition and promotion times. Could we print that baseline alongside the results?

@orthur2 orthur2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding the queued cases.

@ismaeelakin

ismaeelakin commented Nov 8, 2026 •

Copy link
Copy Markdown
Author

Thanks as well for the careful review. I kept upgradable_stages out of the default cargo x bench run so cargo x bench -- --list works, and added a separate CI smoke run for the target. The reader buffer is now reused, so its backing allocation is not freed inside the timed interval. I also report an empty interval with the same clock calls, without subtracting it from the measurements. The default listing, stage smoke run, and target-selection test each passed, cargo x test passed as well.

This branch has not been deployed

No deployments
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