Skip to content

Add priority heap benchmarks#183

Merged
samuel-williams-shopify merged 1 commit into
mainfrom
native-priority-heap
Jun 13, 2026
Merged

Add priority heap benchmarks#183
samuel-williams-shopify merged 1 commit into
mainfrom
native-priority-heap

Conversation

@samuel-williams-shopify

Copy link
Copy Markdown
Contributor

Summary

  • Add benchmark/io/event/priority_heap.rb using sus-fixtures-benchmark.
  • Cover priority heap push, concat, pop, heapify, and delete_if workloads.
  • Capture the findings from evaluating a targeted native extension prototype against Ruby and YJIT.

Findings

A targeted native prototype patched the hot PriorityHeap methods from the extension. It improved plain Ruby in several heap-heavy paths, but YJIT generally performed better without adding C maintenance or load-order complexity. The native prototype is not included in this PR; this PR keeps the benchmark so future changes can be evaluated consistently.

Local benchmark results from benchmark/io/event/priority_heap.rb:

Benchmark Ruby Ruby + YJIT Native Prototype
push in-order 573.35ns 469.49ns 512.48ns
push reverse-order 1.19us 752.48ns 695.09ns
concat into empty heap 467.75us 81.11us 131.37us
pop 1.97us 757.72ns 861.19ns
heapify after delete/append 1.17ms 335.63us 485.32us
delete_if half 1.05ms 383.57us 420.06us

Conclusion: YJIT is the better optimization path for the current Ruby heap implementation. A native implementation does not look like a net win unless non-YJIT performance becomes important enough to justify maintaining duplicate heap logic in C.

Verification

  • BUNDLE_WITH='' bundle exec rubocop benchmark/io/event/priority_heap.rb
  • BUNDLE_WITH='' bundle exec sus --verbose benchmark/io/event/priority_heap.rb
  • BUNDLE_WITH='' bundle exec ruby --yjit -S sus --verbose benchmark/io/event/priority_heap.rb

@samuel-williams-shopify samuel-williams-shopify merged commit 39fe48d into main Jun 13, 2026
52 of 58 checks passed
@samuel-williams-shopify samuel-williams-shopify deleted the native-priority-heap branch June 13, 2026 02:12
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