Repository navigation
Add Duel performance regression guards - #3077
Conversation
dblock
left a comment
There was a problem hiding this comment.
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.
c0d54b8 to
04afd23
Compare
|
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, @dblock I'm a yes on a trimmed-down version, details below. What convinced me. The run on this PR changes nothing in 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: What I'd change before merging:
Smaller things: the CHANGELOG entry is missing. It would also help to add a line on how |
|
@ericproulx Thank you for the thoughtful review. I will work on making these changes and push an updated review shortly.
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. |
|
I just shipped Duel 0.2.0 and updated this PR accordingly. @ericproulx, going through your list:
This should be ready for another review now. |
|
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:
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 Two things on permissions:
With those and a shorter YJIT run, I'm a yes. |
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
|
@ericproulx I released Duel 0.3.0 today and updated this PR for it (b78193b and 79c773c). Going through your list:
A few small things came with the move. 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, |
|
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 On your questions:
I also created the With the badge out, I'm a yes. |
@dblock any final thoughts ? |
|
@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 |
I'm good with this when you're good with this @ericproulx! @sferik thank you, needs a rebase |
Danger ReportNo issues found. |
|
@dblock @ericproulx I've rebased this onto |
|
@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
|
@ericproulx rebased (again) from the latest |
This adds Duel, a gem I wrote to catch performance regressions in CI. On every pull request it runs the benchmarks in
duel/againstmasterand 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
presentbenchmarks use a small representer class thatpresentcalls 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 callschange!before eachcompile!.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, onlyduel commentfrom 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, aduel: acceptlabel lets it through, and adding it runs the Duel job again.Closes #2442