Skip to content

Replace socketpair write bench with deterministic partial-send microbench#958

Closed
Kludex wants to merge 1 commit into
mainfrom
sensitize-sync-write-bench
Closed

Replace socketpair write bench with deterministic partial-send microbench#958
Kludex wants to merge 1 commit into
mainfrom
sensitize-sync-write-bench

Conversation

@Kludex
Copy link
Copy Markdown
Member

@Kludex Kludex commented May 17, 2026

Summary

  • The previous test_bench_sync_stream_write_large used a real socket.socketpair() and a draining reader thread. In practice the kernel accepted most sends in one go, so the buffer-slicing loop inside SyncStream.write ran only a handful of times. That meant optimisations targeting that loop (e.g. perf: use memoryview in write() to avoid copies #954) did not produce a detectable delta on CodSpeed.
  • This PR replaces it with test_bench_sync_stream_write_microcopy, which drives SyncStream.write through a _PartialSendSocket that caps send() at 4KB per call. The Python-level slicing loop now runs ~1024 times against a 4MB payload, so any change to that loop is the dominant cost of the bench.
  • Locally verified that flipping buffer = buffer[n:] to view = view[n:] (the perf: use memoryview in write() to avoid copies #954 change) moves this bench from ~13.8ms to <1µs - far above any walltime noise floor.

Test plan

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 17, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
🆕 1 new benchmark
⏩ 1 skipped benchmark1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
🆕 WallTime test_bench_sync_stream_write_microcopy N/A 511.8 ms N/A

Comparing sensitize-sync-write-bench (b2713e5) with main (8d5f182)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@Kludex Kludex closed this May 17, 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.

1 participant