Skip to content

Add Duel performance regression guards - #3077

Merged
ericproulx merged 1 commit into
ruby-grape:masterfrom
sferik:add-duel
Nov 21, 2026
Merged

ericproulx merged 1 commit into
ruby-grape:masterfrom
sferik:add-duel

Conversation

@sferik

@sferik sferik commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This adds Duel, a gem I wrote to catch performance regressions in CI. On every pull request it runs the benchmarks in duel/ against master and the branch side by side, in alternating worker processes, and fails the build if the branch is slower or allocates more. When something regresses, it profiles both versions with StackProf and says which method the extra time went to.

There are 39 benchmarks, and every one is a request sent through an API's Rack interface in memory, the way a server would hand it over, with no server or sockets involved. I went with whole requests rather than calling internal classes because that's what Grape users actually pay for, and because the router, the middleware stack and the endpoint have been tuned so carefully that most of the interesting work happens between them. The env for each request is built outside the measured time, since Grape and Rack write into the env and read rack.input, so reusing one would measure cached work. Each benchmark also checks its status and part of its body once before measuring, so none of them can quietly end up timing a 404.

grape-entity isn't in the development bundle, so the present benchmarks use a small representer class that present calls the same way it calls an Entity. Compiling a 200 route API took about 40 ms, which is longer than a benchmark should run, so the compile benchmark uses 20 routes and calls change! before each compile!.

A full comparison takes about 10 to 12 seconds here when nothing regressed.

The Duel job only reads. The comment on a pull request comes from a second workflow, perf-comment.yml, which runs none of the pull request's code, only duel comment from Duel's gem, and hides Duel's earlier comments as outdated so the newest one is the one in view. If a change is slower on purpose, a duel: accept label lets it through, and adding it runs the Duel job again.

Closes #2442

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

Nice to see you here again @sferik! Interesting idea. I would want to hear an enthusiastic yes from @ericproulx who has been doing performance improvements left and right in grpe to merge it.

Nit, I'd refactor GHA workflows to be reusable so that they don't have to be copy-pasted all over, like we do here.

Thinking out loud, expanding CI to also check perf is something I'm 50/50 on. CI needs to get faster, not slower, to enable AI agents and benchmarks are as expensive as it gets.

Comment thread Rakefile Resolved
@sferik
sferik force-pushed the add-duel branch 2 times, most recently from c0d54b8 to 04afd23 Compare November 12, 2026 21:00
@ericproulx

Copy link
Copy Markdown
Contributor

Thanks @sferik, this is a nice piece of work. The benchmarks cover the paths I've spent the most time on lately: the router's fast paths, the versioner cascade, declared and params.

@dblock I'm a yes on a trimmed-down version, details below.

What convinced me. The run on this PR changes nothing in lib/, so it's effectively an A/A test. All 39 benchmarks came out "same", and across the board it was 0.999 [0.995, 1.002]. Requiring the 99% interval to clear 1.02 keeps false alarms rare. The two checkouts also sit in same-length directories, which matters: I've measured identical code 5% apart under YJIT just because it lived at different paths.

The part I'd value most is the allocation counts. They're near-exact per request, so "this PR allocates more on the hot path" becomes a hard signal rather than a statistical one.

What it will and won't catch. Some benchmarks are noisy on shared runners: [0.839, 1.016] for the halting before, [0.887, 1.020] for the static route. So it'll flag a lost fast path or a per-request O(n) walk, not a 0.3% drift. That's the right trade for CI.

What I'd change before merging:

  1. Run it on pull requests only. The Duel job took 85s, against 42s for our slowest test job (25s median), so it would roughly double time-to-green. I'd drop the push, schedule and merge_group triggers. We squash-merge, so the push run mostly repeats the PR's, and with fail_on: :every_run a noisy push comparison turns master red. A paths: filter on lib/** and duel/** would skip the job entirely for docs and CI changes.
  2. Give it its own Gemfile. As it stands, duel (with fiddle) and stackprof land in every development bundle, including all 25 test jobs on 3.4 and 4.0. We just moved Danger out for the same reason (Use reusable Danger workflow with a separate Gemfile #3062). The Rakefile hook would then need a LoadError guard; as written, it already fails when the development group isn't installed.
  3. Pin the gem in perf-comment.yml. That job installs duel ~> 0.1.8 with a pull-requests: write token, so any future 0.1.x release would run with that token without review. An exact version, bumped on purpose, would be safer.
  4. A reusable workflow, as dblock suggested. If Duel shipped one, the way we consume Danger's, grape's side would be a few lines and fixes would arrive with Duel releases instead of by copy-paste. It would also replace the ~210 lines of YAML here.
  5. Consider YJIT. The workflow measures the interpreter, but Rails turns YJIT on by default, and some Grape changes move differently under it. If there's budget for only one mode, I'd measure YJIT.

Smaller things: the CHANGELOG entry is missing. It would also help to add a line on how duel/ relates to benchmark/, which already has grape_on_rack and version_throughput, so contributors know where a new scenario goes.

@sferik

sferik commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@ericproulx Thank you for the thoughtful review. I will work on making these changes and push an updated review shortly.

Nit, I'd refactor GHA workflows to be reusable so that they don't have to be copy-pasted all over, like we do here.

I have added this feature on Duel’s main branch, which I’m hoping to release tomorrow. I’ll be sure to update the PR to use that as well.

@sferik

sferik commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

I just shipped Duel 0.2.0 and updated this PR accordingly.

@ericproulx, going through your list:

  1. Pull requests only. The push, schedule and merge_group triggers are gone, and a paths: filter (lib/**, duel/**, .duel.rb, the gemspec, Duel's Gemfile and the workflow itself) skips the job for docs and CI changes (10283d6). Since it no longer runs on pushes, a noisy comparison can't turn master red.
  2. Its own Gemfile. Duel and StackProf live in gemfiles/duel.gemfile, out of every other bundle (as you did with Danger), and the Rakefile hook rescues LoadError (7e58998).
  3. Pinning. gemfiles/duel.gemfile pins duel to an exact version, now 0.2.0 (9c12ab3, bumped in 9ee0844).
  4. A reusable workflow. The callers pass in what's grape's own (Ruby 4.0, YJIT, and its Gemfile), so fixes come with Duel's releases rather than by copy-paste (9ee0844).
  5. YJIT. It measures with YJIT on now (a70e1c6), on Ruby 4.0.

This should be ready for another review now.

@ericproulx

Copy link
Copy Markdown
Contributor

Thanks @sferik, that covers everything on my list. Moving it into Duel's reusable workflows is a nice result for other projects too.

I approved the Perf run for c8becae and ran it twice (run). The setup works: Duel's own bundle, YJIT on in the workers, the push-only jobs skipped, and no false alarms either time. We want to keep YJIT on, but it changes the cost a lot:

Interpreter (Nov 10) YJIT, first run YJIT, re-run
Duel job 85s 4m42s 5m23s
Undecided 2/39 29/39 17/39
Across the board [0.995, 1.002] same [0.989, 1.009] undecided [0.997, 1.005] same

Most of the extra time looks like YJIT warm-up. Each benchmark runs until steady for up to 10s, two at a time on the standard runner, so that's up to ~195s before any measuring starts. Our requests take tens of µs, so YJIT has compiled everything long before that. Could you try c.warm = 2 in .duel.rb and see where the job lands? If it's still well over two minutes, I'd rather trim some of the overlapping scenarios (8 routing, 7 params, 5 versioning) than turn YJIT off.

Two things on permissions:

  1. The exact pin from 9c12ab3 got lost in the move to the reusable workflows. duel-comment.yml at v0.2.0 runs gem install duel --version '~> 0.2.0', and that's the job holding pull-requests: write. Could Duel's comment workflow install exactly its own version? On our side, could both uses: point at the commit rather than the tag, e.g. sferik/duel-ruby/.github/workflows/duel.yml@40e15218e51e80674e1faaaebb9003a7324c0bc6 # v0.2.0, since a tag can be moved?
  2. c8becae grants contents: write to a pull_request workflow, because GitHub checks every called job's permissions, including the push-only ones we leave off. So branches pushed to this repo get a write grant. The job that runs the branch's code narrows it back to read, but only as long as Duel's file at that reference keeps doing so. Duel's ci.md shows callers granting contents: read, though, so one of the two seems off. If GitHub really does require write, could the commit-comment, mark-passed and badge jobs move into a reusable workflow of their own, so a pull-request-only caller can grant read?

With those and a shorter YJIT run, I'm a yes.

sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 19, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 19, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 19, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 19, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
The jobs of Duel's workflows that hold a write permission (Comment on
the commit, Mark the commit passed and Update the badge, with
contents: write, and the Perf comment workflow's, with
pull-requests: write) installed the newest Duel of their minor version
(gem install duel --version '~> 0.2.1'), so a release after the one a
project chose would run with that permission. The review of Duel's
workflows in grape asked for exactly the release instead:
ruby-grape/grape#3077 (comment)

Now each installs exactly the release that wrote it: the reusable
workflows their own, and the workflows duel init and duel-rails's
generator write the one they were written with (duel init --check
says when that's older). RubyGems never takes a version again, so that
release can't change. Duel::Comment::SINCE goes with the range.

A caller can pin Duel's reusable workflows by commit, but that didn't
pin the actions inside them (ruby/setup-ruby@v1, say), whose tags can
move too. Now every action Duel's workflows use is named by its commit,
with its release beside it for Dependabot, and a test sees that every
template's is. docs/ci.md shows how to name Duel's own workflows by
commit.
sferik added a commit to sferik/duel-ruby that referenced this pull request Nov 20, 2026
A Perf workflow that calls Duel's reusable one granted the call
contents: write, as GitHub checks every job of a called workflow
against what the caller grants, whether the job runs or not, and the
jobs for a push (Comment on the commit, Mark the commit passed, Update
the badge) write to the repository. So a pull request's run was granted
a write, too, and only the Duel job's own contents: read, in Duel's
file at that reference, kept the job that runs the branch's code from
it. The review of Duel's workflows in grape asked for a caller that
grants a pull request's run reading alone:
ruby-grape/grape#3077 (comment)

Now those jobs are Duel's push workflow's (duel-push.yml), and the Perf
workflow (duel.yml) has the Duel job alone. duel init writes two calls:
the Duel job's, which grants contents: read, and the push workflow's,
which needs it, runs only for a push, grants contents: write, and
passes on what the Duel job said (its comment, status and passed
outputs) and how its call ended (needs.duel.result), which the badge
shows. The badge input moves to the push workflow.

The jobs are one template (perf-push-jobs.yml.erb), the whole Perf
workflow's as before, so --standalone's workflow and duel-rails's don't
change. The push workflow has them with what they took from the Duel
job (needs.duel) as its inputs. actionlint checks a caller that duel
init writes against the two workflows. docs/ci.md and AGENT_PROMPT.md
describe the two calls, and the passed output is described as the
branch it is, not true.
@sferik

sferik commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

@ericproulx I released Duel 0.3.0 today and updated this PR for it (b78193b and 79c773c). Going through your list:

  1. YJIT's warm-up. .duel.rb now sets c.warm = 2, so each benchmark warms up for 2 seconds instead of until it's steady (for up to 10). I ran the Perf workflow twice on a standard runner, with YJIT, in a PR in my fork whose base is this PR's base, so it compared Grape's code with itself (run, attempts 1 and 2):

    Interpreter (Nov 10) YJIT, first run YJIT, re-run YJIT, c.warm = 2 YJIT, c.warm = 2, re-run
    Duel job 85s 4m42s 5m23s 2m38s 2m41s
    Undecided 2/39 29/39 17/39 2/39 5/39
    Across the board [0.995, 1.002] same [0.989, 1.009] undecided [0.997, 1.005] same [0.995, 1.002] same [0.988, 0.999] same

    No false alarms either time. It's still a bit over two minutes, so if you'd like it shorter, I'm happy to trim the overlapping routing, params and versioning scenarios. Just tell me which ones you'd keep. (Duel 0.3.0 calls "undecided" "unsettled" now, so that's what the report will say.)

  2. The exact pin. Both uses: point at the commit that Duel 0.3.0's tag names, rather than the tag: sferik/duel-ruby/.github/workflows/duel.yml@14e3fd0c230d19872715e4e3ecd30955825f1233 # v0.3.0, and the same for duel-comment.yml. Duel's comment workflow at that commit installs exactly its own version (gem install duel --version '0.3.0'), and gemfiles/duel.gemfile asks for exactly 0.3.0 too.

  3. contents: write. You were right that GitHub requires it for every job of the called workflow, run or not. Duel 0.3.0 moves the jobs that write for a push (commenting on the commit, marking it passed and keeping the badge) into a reusable workflow of their own, which this workflow doesn't call. So the Perf workflow now grants contents: read, and nothing in it can write to the repository.

A few small things came with the move. yjit: true is now jit: yjit, and the Duel job no longer takes accept-label, since Duel reads it from .duel.rb. .duel.rb leaves the label to Duel's default (duel: accept), commented out. I also added Duel's badge to the README's row of badges, linked to the Perf workflow's runs. It's the always-green one, since this workflow has no push jobs to keep a red one. I'm happy to take it out if you'd rather not have it.

If you'd like a badge that turns red when a push to master regresses, that's possible now without touching this workflow: a second one, perf-push.yml, that runs only for pushes to master (with the same paths:), whose Duel job only reads, and whose badge job alone gets contents: write and runs none of the code. With c.fail_on = :pull_requests, a noisy push comparison only warns, so master's check stays green. It costs a Duel run (about 2m40s) per push to master that touches lib/ or the benchmarks. I'm happy to add it if you want it.

@ericproulx

Copy link
Copy Markdown
Contributor

Thanks @sferik, that's everything. I checked the 0.3.0 workflows at 14e3fd0c: the comment workflow installs exactly 0.3.0, the Perf workflow only reads, and the comment is posted only when the pull request's head is still the commit the run measured.

I approved the Perf run here for 79c773c (run). It passed in 2m45s, 147s of it measuring. None of the 39 benchmarks came out slower or faster, 7 were unsettled, and across the board was 0.997 [0.992, 1.002] same.

On your questions:

  1. Timing: let's keep all 39. Measuring takes about 3.7s a benchmark, so getting under two minutes would mean dropping about 10 of them. That's not worth 40s on a check that only runs when lib/ changes.
  2. The badge: I'd rather leave it out. It's always green, so unlike the other badges it doesn't report anything.
  3. perf-push.yml: not for now. Pull requests only, as we said. We can add it later if we find we're missing a signal on master.

I also created the duel: accept label, so it's there the first time a pull request has to be slower on purpose.

With the badge out, I'm a yes.

@ericproulx

Copy link
Copy Markdown
Contributor

Thanks @sferik, that's everything. I checked the 0.3.0 workflows at 14e3fd0c: the comment workflow installs exactly 0.3.0, the Perf workflow only reads, and the comment is posted only when the pull request's head is still the commit the run measured.

I approved the Perf run here for 79c773c (run). It passed in 2m45s, 147s of it measuring. None of the 39 benchmarks came out slower or faster, 7 were unsettled, and across the board was 0.997 [0.992, 1.002] same.

On your questions:

  1. Timing: let's keep all 39. Measuring takes about 3.7s a benchmark, so getting under two minutes would mean dropping about 10 of them. That's not worth 40s on a check that only runs when lib/ changes.
  2. The badge: I'd rather leave it out. It's always green, so unlike the other badges it doesn't report anything.
  3. perf-push.yml: not for now. Pull requests only, as we said. We can add it later if we find we're missing a signal on master.

I also created the duel: accept label, so it's there the first time a pull request has to be slower on purpose.

With the badge out, I'm a yes.

@dblock any final thoughts ?

@ericproulx

Copy link
Copy Markdown
Contributor

@sferik One more small thing: this also answers #2442, dblock's request for a memory check on every pull request (a benchmark run before and after the change, its allocations compared, and a comment on the pull request), and goes further with CPU time. Could you add Closes #2442 to the description, so the issue closes when this merges?

@dblock

dblock commented Nov 20, 2026

Copy link
Copy Markdown
Member

@dblock any final thoughts ?

I'm good with this when you're good with this @ericproulx!

@sferik thank you, needs a rebase

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@sferik

sferik commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@dblock @ericproulx I've rebased this onto master and squashed it into a single commit with Closes #2442 in the commit message.

@ericproulx

Copy link
Copy Markdown
Contributor

@sferik I've merged a couple of PRs, you need to rebase again. You're the next in line :)

Duel (https://github.com/sferik/duel-ruby) runs the benchmarks in duel/
on the branch a pull request targets and on the pull request, side by
side, and fails the Perf workflow when the pull request is slower or
allocates more. It's the memory check on every pull request that
ruby-grape#2442 asks for, and it
measures CPU time too.

The 39 benchmarks send requests through an API's Rack interface in
memory, with YJIT on, in a bundle of their own (gemfiles/duel.gemfile,
which pins Duel to an exact version). The Perf workflow runs on pull
requests that touch the code or the benchmarks, calls Duel's reusable
workflow at the commit Duel 0.3.0's tag names, and only reads. A
second workflow comments on the pull request with the report, running
none of its code.

Closes ruby-grape#2442
@sferik

sferik commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

@ericproulx rebased (again) from the latest master. It should merge cleanly.

@ericproulx
ericproulx merged commit b47794a into ruby-grape:master Nov 21, 2026
26 of 27 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.

Add a memory usage check

3 participants