Skip to content

Inline GC fastpath in ZJIT for newhash instruction - #17717

Merged
eightbitraptor merged 8 commits into
ruby:masterfrom
eightbitraptor:mvh-zjit-inline-fast-path
Jul 8, 2026
Merged

Inline GC fastpath in ZJIT for newhash instruction#17717
eightbitraptor merged 8 commits into
ruby:masterfrom
eightbitraptor:mvh-zjit-inline-fast-path

Conversation

@eightbitraptor

Copy link
Copy Markdown
Member

This extends the ZJIT GC fast path to the newhash instruction for empty hashes.

This was verified in a stripped down benchmarking environment, using the following micro-benchmark in ruby-bench:

def run(max)
  i = 0
  while i < max
    h = {}
    i += 1
  end
end

require_relative '../harness/loader.rb'

run_benchmark(50) do
  50.times do
    run(500_000)
  end
end

This patch resulted in a ~30% speedup.

master: ruby 4.1.0dev (2026-07-07T14:04:07Z master c51b1596c0) +ZJIT +PRISM [x86_64-linux]
experiment: ruby 4.1.0dev (2026-07-07T19:27:04Z mvh-zjit-inline-fa.. 60730f1aa1) +ZJIT +PRISM [x86_64-linux]

-----  ------------  ---------------  ------------------  -----------------
bench   master (ms)  experiment (ms)  experiment 1st itr  master/experiment
hash   682.3 ± 0.7%     518.0 ± 1.0%               1.082              1.317
-----  ------------  ---------------  ------------------  -----------------

Legend:
- experiment 1st itr: ratio of master/experiment time for the first benchmarking iteration.
- master/experiment: ratio of master/experiment time. Higher is better for experiment. Above 1 represents a speedup.

@matzbot
matzbot requested a review from a team July 7, 2026 20:05
Comment thread zjit/src/codegen.rs Outdated
@eightbitraptor
eightbitraptor force-pushed the mvh-zjit-inline-fast-path branch from f7e29d9 to e1fdc71 Compare July 7, 2026 20:28
Comment thread zjit/src/codegen.rs Outdated

@peterzhu2118 peterzhu2118 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@eightbitraptor
eightbitraptor requested a review from tekknolagi July 8, 2026 08:07
Comment thread zjit/src/codegen/gc_fastpath.rs Outdated
Comment thread zjit/src/cruby.rs Outdated
Comment thread hash.c Outdated

@tekknolagi tekknolagi 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.

lgtm with comments

Comment thread zjit/src/codegen.rs Outdated
Comment thread zjit/src/codegen/gc_fastpath.rs Outdated
eightbitraptor and others added 5 commits July 8, 2026 19:08
This extends the ZJIT GC fast path to the newhash instruction for empty
hashes.

This was verified in a stripped down benchmarking environment, using the
following micro-benchmark in ruby-bench:

```
def run(max)
  i = 0
  while i < max
    h = {}
    i += 1
  end
end

require_relative '../harness/loader.rb'

run_benchmark(50) do
  50.times do
    run(500_000)
  end
end
```

This patch resulted in a ~30% speedup.

```
master: ruby 4.1.0dev (2026-07-07T14:04:07Z master c51b159) +ZJIT +PRISM [x86_64-linux]
experiment: ruby 4.1.0dev (2026-07-07T19:27:04Z mvh-zjit-inline-fa.. 60730f1) +ZJIT +PRISM [x86_64-linux]

-----  ------------  ---------------  ------------------  -----------------
bench   master (ms)  experiment (ms)  experiment 1st itr  master/experiment
hash   682.3 ± 0.7%     518.0 ± 1.0%               1.082              1.317
-----  ------------  ---------------  ------------------  -----------------

Legend:
- experiment 1st itr: ratio of master/experiment time for the first benchmarking iteration.
- master/experiment: ratio of master/experiment time. Higher is better for experiment. Above 1 represents a speedup.
```
@eightbitraptor
eightbitraptor force-pushed the mvh-zjit-inline-fast-path branch from a6a2d5c to d9193cb Compare July 8, 2026 18:49
@eightbitraptor
eightbitraptor requested a review from XrXr July 8, 2026 18:50

@XrXr XrXr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM minus CI failure and one comment

Comment thread test/ruby/test_zjit.rb
@eightbitraptor
eightbitraptor force-pushed the mvh-zjit-inline-fast-path branch 2 times, most recently from f931930 to 36c974b Compare July 8, 2026 21:13
@eightbitraptor
eightbitraptor force-pushed the mvh-zjit-inline-fast-path branch from 36c974b to 0ad878a Compare July 8, 2026 21:25
@eightbitraptor
eightbitraptor enabled auto-merge (rebase) July 8, 2026 22:19
@eightbitraptor
eightbitraptor merged commit f1ce5fc into ruby:master Jul 8, 2026
130 of 132 checks passed
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.

5 participants