Skip to content

[pull] master from ruby:master#831

Merged
pull[bot] merged 10 commits intoturkdevops:masterfrom
ruby:master
Mar 7, 2026
Merged

[pull] master from ruby:master#831
pull[bot] merged 10 commits intoturkdevops:masterfrom
ruby:master

Conversation

@pull
Copy link

@pull pull bot commented Mar 7, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

kddnewton and others added 10 commits March 6, 2026 21:26
Adds runtime execution tracking for ZJIT-compiled iseqs so we can identify which compiled methods are called most frequently.

**Why?**
  1. Determining what can be optimized based on how often it's called: knowing call frequency helps prioritize which methods are worth spending time on, and focus improvements on the hottest paths, so ZJIT work has the most impact.
  2. Memory eviction: ZJIT has a fixed allocated code region size, and when it fills up it stops compiling new methods. This data could help decide which low-usage methods to drop to make room. 
 

**How?**
A `HashMap<String, Box<u64>>` is added to `ZJITState` mapping each compiled iseq's location string to a counter.

The counter is an `IncrCounterPtr` HIR instruction inserted into the JIT entry block (bb2) during HIR construction in `compile_jit_entry_block`, before the block gets lowered to machine code by `gen_function`.

  The placement here matters `jit_entry_ptrs` are recorded via `pos_marker` on the `EntryPoint` instruction. By inserting the counter in the HIR it ends up after EntryPoint in the instruction stream, so it actually gets executed on every JIT call. My first attempt emitted the counter directly in `gen_function` before writing the block label, which
   silently placed it before EntryPoint — making it unreachable since stubs jump to the EntryPoint address, skipping the counter entirely for certain methods.

  Box<u64> is owned by ZJITState for the lifetime of the program so the pointer stays stable across HashMap resizes. Everything is gated behind --zjit-stats, exposed through RubyVM::ZJIT.runtime_stats, and
  printed as "hottest code paths."

Ran zjit-stats on the lobsters [benchmark](https://github.com/ruby/ruby-bench/blob/main/benchmarks/lobsters/benchmark.rb)
```cli
Top-20 hottest code paths (20.9% of total 48,150,957):
                                                        []@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activesupport-8.1.1/lib/active_support/isolated_execution_state.rb:32: 996,342 ( 2.1%)
                                                 attribute_types@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activemodel-8.1.1/lib/active_model/attribute_registration.rb:38: 796,188 ( 1.7%)
                                                  block in redefine@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activesupport-8.1.1/lib/active_support/class_attribute.rb:15: 702,587 ( 1.5%)
                                                                    klass@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/reflection.rb:423: 645,927 ( 1.3%)
                                               _read_attribute@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/attribute_methods/read.rb:39: 601,522 ( 1.2%)
            get_or_default@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/concurrent-ruby-1.3.5/lib/concurrent-ruby/concurrent/collection/map/non_concurrent_map_backend.rb:111: 477,348 ( 1.0%)
                                                                  fetch@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/type/type_map.rb:19: 469,970 ( 1.0%)
                                                           fetch@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/concurrent-ruby-1.3.5/lib/concurrent-ruby/concurrent/map.rb:183: 469,970 ( 1.0%)
                                                  fetch_or_store@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/concurrent-ruby-1.3.5/lib/concurrent-ruby/concurrent/map.rb:205: 469,970 ( 1.0%)
                         extended_type_map_key@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1173: 469,970 ( 1.0%)
                                      type_map@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/connection_adapters/abstract_adapter.rb:1179: 469,941 ( 1.0%)
                                                                         fetch@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/result.rb:76: 449,631 ( 0.9%)
                                                   context@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activesupport-8.1.1/lib/active_support/isolated_execution_state.rb:55: 445,689 ( 0.9%)
                                                                    <<@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/arel/collectors/plain_string.rb:15: 428,350 ( 0.9%)
                                                              foreign_key@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/reflection.rb:559: 405,255 ( 0.8%)
                                                              period@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activesupport-8.1.1/lib/active_support/time_with_zone.rb:79: 400,182 ( 0.8%)
                                                      klass@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/associations/association.rb:166: 346,231 ( 0.7%)
                                                     loaded?@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activerecord-8.1.1/lib/active_record/associations/association.rb:82: 344,651 ( 0.7%)
                                                                                   get_header@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/rack-2.2.19/lib/rack/request.rb:63: 341,545 ( 0.7%)
                                                                        cast@/Users/nerycampusano/.gem/ruby/ruby-zjit/gems/activemodel-8.1.1/lib/active_model/type/value.rb:58: 326,008 ( 0.7%)
```
Returns the author date of the latest commit for the path.
Prefer the date authored the contents over the merged date for the
embedded dates.
@pull pull bot locked and limited conversation to collaborators Mar 7, 2026
@pull pull bot added the ⤵️ pull label Mar 7, 2026
@pull pull bot merged commit 66e61d0 into turkdevops:master Mar 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants