diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b29618fa6..ef742178e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -92,6 +92,11 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false + # Base and head are measured from identical checkouts so that only their code and dependencies differ. + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 + with: + persist-credentials: false + path: tmp/head - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 with: persist-credentials: false @@ -112,15 +117,33 @@ jobs: with: ruby-version: 4.0 bundler-cache: true + - name: Install base and head dependencies + shell: bash + run: | + for side in base head; do + gemfile="$GITHUB_WORKSPACE/tmp/$side/$BUNDLE_GEMFILE" + if [ ! -f "$gemfile" ]; then + echo "::warning::Base has no $BUNDLE_GEMFILE; measuring base with head dependencies" + gemfile="$GITHUB_WORKSPACE/tmp/head/$BUNDLE_GEMFILE" + fi + BUNDLE_GEMFILE="$gemfile" bundle config set --local path "$GITHUB_WORKSPACE/vendor/bundle" + BUNDLE_GEMFILE="$gemfile" bundle config set --local deployment true + BUNDLE_GEMFILE="$gemfile" bundle install --jobs 4 + echo "$(echo "$side" | tr '[:lower:]' '[:upper:]')_BUNDLE_GEMFILE=$gemfile" >> "$GITHUB_ENV" + done - name: Compare performance against base shell: bash env: - PASSES: 5 + # Timings shift more between processes than between passes, so favor more processes. + ROUNDS: 6 + PASSES: 3 BASE_REF: ${{ steps.release.outputs.tag || github.event.pull_request.base.sha }} run: | - for round in 1 2 3; do - VIEW_COMPONENT_LIB=tmp/base/lib bundle exec ruby performance/measure.rb "tmp/performance/base/$round.json" - bundle exec ruby performance/measure.rb "tmp/performance/head/$round.json" + for round in $(seq "$ROUNDS"); do + BUNDLE_GEMFILE="$BASE_BUNDLE_GEMFILE" VIEW_COMPONENT_LIB=tmp/base/lib \ + bundle exec ruby performance/measure.rb "tmp/performance/base/$round.json" + BUNDLE_GEMFILE="$HEAD_BUNDLE_GEMFILE" VIEW_COMPONENT_LIB=tmp/head/lib \ + bundle exec ruby performance/measure.rb "tmp/performance/head/$round.json" done { printf 'Base: `%s`; head: `%s` (pull request merge commit).\n\n' "$BASE_REF" "$GITHUB_SHA" diff --git a/Gemfile.lock b/Gemfile.lock index 70ec103b0..0e1dbb64c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -131,9 +131,9 @@ GEM cruise (0.3.0-x86_64-linux-gnu) cruise (0.3.0-x86_64-linux-musl) csv (3.3.7) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -147,11 +147,11 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) ffi (1.17.4-aarch64-linux-gnu) ffi (1.17.4-aarch64-linux-musl) ffi (1.17.4-arm-linux-gnu) @@ -160,21 +160,21 @@ GEM ffi (1.17.4-x86_64-darwin) ffi (1.17.4-x86_64-linux-gnu) ffi (1.17.4-x86_64-linux-musl) - globalid (1.4.0) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) @@ -537,7 +537,7 @@ CHECKSUMS cruise (0.3.0-x86_64-linux-gnu) sha256=a7bdd7c72307a450a9d37f3c7a90c118230ea6122663b32b8c8e52cad32adfa8 cruise (0.3.0-x86_64-linux-musl) sha256=54ed6809f1d476bf99a3043bc256cca0efed8bbc9df93a55f4e49eac2bbcb7f4 csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8 - cuprite (0.22) sha256=0be36125d65f5fe06a4355413e5518fe81400cf6e5cced26f131295584296509 + cuprite (1.0) sha256=f885cd18364a120374766da4a5fa19b33aaddd520728c1b907e9c8d4f0e7224d date (3.6.0) sha256=18ac945c4e24ebd93534f8eab8c2fd8c5604b3e977105b3798d62a1e8d27b580 diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962 drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373 @@ -545,7 +545,7 @@ CHECKSUMS erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92 erb_lint (0.9.0) sha256=dfb5e40ad839e8d1f0d56ca85ec9a7ac4c9cd966ec281138282f35b323ca7c31 erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9 - ferrum (0.22.0) sha256=d7fe234ba6cc677e2b94c012ae98918e9233666e93ab2979ca6f983e00d9b92d + ferrum (1.0.0) sha256=9bbb859c5ba5d95995e99de71f0744d355f23e1cd7ba81a380988891d5e9d707 ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39 ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564 @@ -554,16 +554,16 @@ CHECKSUMS ffi (1.17.4-x86_64-darwin) sha256=aa70390523cf3235096cf64962b709b4cfbd5c082a2cb2ae714eb0fe2ccda496 ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e - globalid (1.4.0) sha256=037f12fbf1d9d7a014d501c2d5c77356fd4ddd96d7a7991d6700bba96706f427 + globalid (1.5.0) sha256=2b38ddb12f0765feba4a38b71032d8917ee341aaec0931f5d362eb5b192de4a3 haml (7.5.2) sha256=fcef494c3c5f173f5b38338b1ade7e65b1de37194919b901f047cac76f370d42 - herb (0.11.2-aarch64-linux-gnu) sha256=b8015cba548ff79f04c69dd9ccf92a8dc8900fca8a0fc23b000f92fdf7219842 - herb (0.11.2-aarch64-linux-musl) sha256=0b41e988a6c81cb05cacfb3a5444d729fb1c41970bfe594fbdc91319376ce8cc - herb (0.11.2-arm-linux-gnu) sha256=f7f7d1ecf69670a39911b7d159705e55d2f0f9f3e935cf27f29a02e4723a6445 - herb (0.11.2-arm-linux-musl) sha256=677d0e8676f96448c4e0a82da6e772c90f6de43e48ef13987f57518472d69568 - herb (0.11.2-arm64-darwin) sha256=7a5e23818c3f784690384fc111eae50d6993723eb0c172a8a72d0be167281d78 - herb (0.11.2-x86_64-darwin) sha256=3c44bbfac81d95e5760fa6e20054c4ac6d2aeaca28dcee5df83dcd43adf84897 - herb (0.11.2-x86_64-linux-gnu) sha256=2627fe909e7e6b0548926573d87a2e12b6d65bc85964832d34abf5ba165bfc37 - herb (0.11.2-x86_64-linux-musl) sha256=aa6e7aa38d44de757d3076e331234f55ed2f392c2bd0203a3aa4ceea0b6bdd3e + herb (0.11.3-aarch64-linux-gnu) sha256=cf0ff5ea95df4709c4afe6f5f0c574c5943a7c3eff1b4eee745af77359d2d8b0 + herb (0.11.3-aarch64-linux-musl) sha256=f0b2cdb5be9f444a55978ac5cf5769da18b6c3ff093c4d43e02d9b0286dc0ea7 + herb (0.11.3-arm-linux-gnu) sha256=fcbd9c6d38d733d8f57f691c807358fa9bafe9d0d46bdac644ad5502f6ff408a + herb (0.11.3-arm-linux-musl) sha256=db0fe7ec45d88c2f3e865b1216ba248edce6a107c5d400252d14d73ddf1190e9 + herb (0.11.3-arm64-darwin) sha256=2455cb33c85056aee29b72759ac272c63daa77f95c40d15c134b27cb462dfbb6 + herb (0.11.3-x86_64-darwin) sha256=f67dc74663fd3247f8cbaaf8d9cd5693b740b785130b336e2f08428beb9f8264 + herb (0.11.3-x86_64-linux-gnu) sha256=a1f5d4b26cb097ce1d6785c7dd24f4551c43cf3d5713d1aa1898f440b86d2799 + herb (0.11.3-x86_64-linux-musl) sha256=af5634e0402d8e552bd5d0b332016852d34967d5d48aa9c432572608fe3070fe i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5 io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5 irb (1.19.0) sha256=55ee56acbdd6c9fe06a2e6909f46a24e5c41f45f16906bab04e8049cf46f1d27 diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 99b79ffa1..3c20e917a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* Benchmark pull requests against the base branch's dependencies and compare absolute component times to catch performance regressions from dependency updates, and run more benchmark processes to reduce noise. + + *Joel Hawksley* + * Enable all Herb lint rules, template formatting, Tailwind class sorting, and editor support for development. *Joel Hawksley* diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 61c894cd7..7624bc202 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -110,9 +110,9 @@ bundle exec appraisal rails-8.0 rake ### Performance -CI compares each pull request against its base branch on Rails 8.1 and Rails main. For each rendering scenario in `performance/measure.rb`, it divides the component render time by the render time of an equivalent partial. It also measures cold component digests relative to cold partial digests, clearing Action View's digest caches and using a new lookup context for every call. +CI compares each pull request against its base branch on Rails 8.1 and Rails main, measuring the base with its own dependencies so dependency updates are compared too. The report lists any dependency changes. For each rendering scenario in `performance/measure.rb`, it divides the component render time by the render time of an equivalent partial. It also measures cold component digests relative to cold partial digests, clearing Action View's digest caches and using a new lookup context for every call. -The digest and boot scenarios use 300 generated ERB components and 300 generated Slim components. Each renders another component and includes a shared helper that references multiple components, exercising overlapping and cyclic dependencies. The boot scenario divides the time spent in ViewComponent (requiring it, loading components, compiling them, and precomputing digests) by the rest of boot. CI fails if any scenario's ratio is more than 5% higher than the baseline's ratio. +The digest and boot scenarios use 300 generated ERB components and 300 generated Slim components. Each renders another component and includes a shared helper that references multiple components, exercising overlapping and cyclic dependencies. The boot scenario divides the time spent in ViewComponent (requiring it, loading components, compiling them, and precomputing digests) by the rest of boot. CI fails if any scenario's ratio is more than 5% higher than the baseline's ratio. Ratios cancel out runner noise but miss changes, such as dependency updates, that slow components and partials alike, so CI also fails if any scenario's absolute component time, measured on the same runner, is more than 10% higher than the baseline's. The executor scenario runs empty `app.executor.wrap` jobs on four threads in development with template caching disabled and the polling file watcher. It uses the generated components plus 600 model directories and compares against Rails without ViewComponent, catching template scans on executor-only paths such as Action Cable broadcasts. @@ -122,7 +122,8 @@ To run the comparison locally: ```command git worktree add tmp/base main -VIEW_COMPONENT_LIB=tmp/base/lib bundle exec ruby performance/measure.rb tmp/performance/base.json +BUNDLE_GEMFILE=tmp/base/Gemfile bundle install +BUNDLE_GEMFILE=tmp/base/Gemfile VIEW_COMPONENT_LIB=tmp/base/lib bundle exec ruby performance/measure.rb tmp/performance/base.json bundle exec ruby performance/measure.rb tmp/performance/head.json bundle exec ruby performance/compare.rb tmp/performance/base.json tmp/performance/head.json ``` diff --git a/gemfiles/rails_7.1.gemfile.lock b/gemfiles/rails_7.1.gemfile.lock index 55075864a..feb0499e3 100644 --- a/gemfiles/rails_7.1.gemfile.lock +++ b/gemfiles/rails_7.1.gemfile.lock @@ -152,21 +152,21 @@ GEM base64 (~> 0.2) concurrent-ruby (~> 1.1) websocket-driver (~> 0.7) - globalid (1.4.0) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) diff --git a/gemfiles/rails_7.2.gemfile.lock b/gemfiles/rails_7.2.gemfile.lock index 034f32990..7b3152078 100644 --- a/gemfiles/rails_7.2.gemfile.lock +++ b/gemfiles/rails_7.2.gemfile.lock @@ -125,9 +125,9 @@ GEM cruise (0.3.0-x86_64-darwin) cruise (0.3.0-x86_64-linux-gnu) cruise (0.3.0-x86_64-linux-musl) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -141,26 +141,26 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) - globalid (1.4.0) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) diff --git a/gemfiles/rails_8.0.gemfile.lock b/gemfiles/rails_8.0.gemfile.lock index ec3811166..8c2e45e68 100644 --- a/gemfiles/rails_8.0.gemfile.lock +++ b/gemfiles/rails_8.0.gemfile.lock @@ -122,9 +122,9 @@ GEM cruise (0.3.0-x86_64-darwin) cruise (0.3.0-x86_64-linux-gnu) cruise (0.3.0-x86_64-linux-musl) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -138,26 +138,26 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) - globalid (1.4.0) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) diff --git a/gemfiles/rails_8.1.gemfile.lock b/gemfiles/rails_8.1.gemfile.lock index 58d09117b..b87b382c5 100644 --- a/gemfiles/rails_8.1.gemfile.lock +++ b/gemfiles/rails_8.1.gemfile.lock @@ -131,9 +131,9 @@ GEM cruise (0.3.0-x86_64-linux-gnu) cruise (0.3.0-x86_64-linux-musl) csv (3.3.7) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -147,11 +147,11 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) ffi (1.17.4-aarch64-linux-gnu) ffi (1.17.4-aarch64-linux-musl) ffi (1.17.4-arm-linux-gnu) @@ -160,21 +160,21 @@ GEM ffi (1.17.4-x86_64-darwin) ffi (1.17.4-x86_64-linux-gnu) ffi (1.17.4-x86_64-linux-musl) - globalid (1.4.0) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) diff --git a/gemfiles/rails_main.gemfile.lock b/gemfiles/rails_main.gemfile.lock index a09913e74..24b2a7cf9 100644 --- a/gemfiles/rails_main.gemfile.lock +++ b/gemfiles/rails_main.gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: dde4894f1af1121ea65e48d9abd5a8469d4b80e5 + revision: af32ebb8cb4ebf46fd70f6f2faeb30e0c1cbe998 branch: main specs: actioncable (8.2.0.alpha) @@ -170,9 +170,9 @@ GEM cruise (0.3.0-x86_64-linux-gnu) cruise (0.3.0-x86_64-linux-musl) csv (3.3.7) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -186,11 +186,11 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) ffi (1.17.4-aarch64-linux-gnu) ffi (1.17.4-aarch64-linux-musl) ffi (1.17.4-arm-linux-gnu) @@ -199,21 +199,21 @@ GEM ffi (1.17.4-x86_64-darwin) ffi (1.17.4-x86_64-linux-gnu) ffi (1.17.4-x86_64-linux-musl) - globalid (1.4.0) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2-aarch64-linux-gnu) - herb (0.11.2-aarch64-linux-musl) - herb (0.11.2-arm-linux-gnu) - herb (0.11.2-arm-linux-musl) - herb (0.11.2-arm64-darwin) - herb (0.11.2-x86_64-darwin) - herb (0.11.2-x86_64-linux-gnu) - herb (0.11.2-x86_64-linux-musl) + herb (0.11.3-aarch64-linux-gnu) + herb (0.11.3-aarch64-linux-musl) + herb (0.11.3-arm-linux-gnu) + herb (0.11.3-arm-linux-musl) + herb (0.11.3-arm64-darwin) + herb (0.11.3-x86_64-darwin) + herb (0.11.3-x86_64-linux-gnu) + herb (0.11.3-x86_64-linux-musl) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) @@ -558,7 +558,7 @@ CHECKSUMS cruise (0.3.0-x86_64-linux-gnu) sha256=a7bdd7c72307a450a9d37f3c7a90c118230ea6122663b32b8c8e52cad32adfa8 cruise (0.3.0-x86_64-linux-musl) sha256=54ed6809f1d476bf99a3043bc256cca0efed8bbc9df93a55f4e49eac2bbcb7f4 csv (3.3.7) sha256=15a3f16f6628da8664d455eb634e7f22031bcf53044923caf56975109e71b9f8 - cuprite (0.22) sha256=0be36125d65f5fe06a4355413e5518fe81400cf6e5cced26f131295584296509 + cuprite (1.0) sha256=f885cd18364a120374766da4a5fa19b33aaddd520728c1b907e9c8d4f0e7224d date (3.6.0) sha256=18ac945c4e24ebd93534f8eab8c2fd8c5604b3e977105b3798d62a1e8d27b580 diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962 drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373 @@ -566,7 +566,7 @@ CHECKSUMS erb (6.0.7) sha256=c5ca6dc25b0ef974a44dc8f59fe847577122483b1968a38dec305c60bf91ee92 erb_lint (0.9.0) sha256=dfb5e40ad839e8d1f0d56ca85ec9a7ac4c9cd966ec281138282f35b323ca7c31 erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9 - ferrum (0.22.0) sha256=d7fe234ba6cc677e2b94c012ae98918e9233666e93ab2979ca6f983e00d9b92d + ferrum (1.0.0) sha256=9bbb859c5ba5d95995e99de71f0744d355f23e1cd7ba81a380988891d5e9d707 ffi (1.17.4-aarch64-linux-gnu) sha256=b208f06f91ffd8f5e1193da3cae3d2ccfc27fc36fba577baf698d26d91c080df ffi (1.17.4-aarch64-linux-musl) sha256=9286b7a615f2676245283aef0a0a3b475ae3aae2bb5448baace630bb77b91f39 ffi (1.17.4-arm-linux-gnu) sha256=d6dbddf7cb77bf955411af5f187a65b8cd378cb003c15c05697f5feee1cb1564 @@ -575,16 +575,16 @@ CHECKSUMS ffi (1.17.4-x86_64-darwin) sha256=aa70390523cf3235096cf64962b709b4cfbd5c082a2cb2ae714eb0fe2ccda496 ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e - globalid (1.4.0) sha256=037f12fbf1d9d7a014d501c2d5c77356fd4ddd96d7a7991d6700bba96706f427 + globalid (1.5.0) sha256=2b38ddb12f0765feba4a38b71032d8917ee341aaec0931f5d362eb5b192de4a3 haml (7.5.2) sha256=fcef494c3c5f173f5b38338b1ade7e65b1de37194919b901f047cac76f370d42 - herb (0.11.2-aarch64-linux-gnu) sha256=b8015cba548ff79f04c69dd9ccf92a8dc8900fca8a0fc23b000f92fdf7219842 - herb (0.11.2-aarch64-linux-musl) sha256=0b41e988a6c81cb05cacfb3a5444d729fb1c41970bfe594fbdc91319376ce8cc - herb (0.11.2-arm-linux-gnu) sha256=f7f7d1ecf69670a39911b7d159705e55d2f0f9f3e935cf27f29a02e4723a6445 - herb (0.11.2-arm-linux-musl) sha256=677d0e8676f96448c4e0a82da6e772c90f6de43e48ef13987f57518472d69568 - herb (0.11.2-arm64-darwin) sha256=7a5e23818c3f784690384fc111eae50d6993723eb0c172a8a72d0be167281d78 - herb (0.11.2-x86_64-darwin) sha256=3c44bbfac81d95e5760fa6e20054c4ac6d2aeaca28dcee5df83dcd43adf84897 - herb (0.11.2-x86_64-linux-gnu) sha256=2627fe909e7e6b0548926573d87a2e12b6d65bc85964832d34abf5ba165bfc37 - herb (0.11.2-x86_64-linux-musl) sha256=aa6e7aa38d44de757d3076e331234f55ed2f392c2bd0203a3aa4ceea0b6bdd3e + herb (0.11.3-aarch64-linux-gnu) sha256=cf0ff5ea95df4709c4afe6f5f0c574c5943a7c3eff1b4eee745af77359d2d8b0 + herb (0.11.3-aarch64-linux-musl) sha256=f0b2cdb5be9f444a55978ac5cf5769da18b6c3ff093c4d43e02d9b0286dc0ea7 + herb (0.11.3-arm-linux-gnu) sha256=fcbd9c6d38d733d8f57f691c807358fa9bafe9d0d46bdac644ad5502f6ff408a + herb (0.11.3-arm-linux-musl) sha256=db0fe7ec45d88c2f3e865b1216ba248edce6a107c5d400252d14d73ddf1190e9 + herb (0.11.3-arm64-darwin) sha256=2455cb33c85056aee29b72759ac272c63daa77f95c40d15c134b27cb462dfbb6 + herb (0.11.3-x86_64-darwin) sha256=f67dc74663fd3247f8cbaaf8d9cd5693b740b785130b336e2f08428beb9f8264 + herb (0.11.3-x86_64-linux-gnu) sha256=a1f5d4b26cb097ce1d6785c7dd24f4551c43cf3d5713d1aa1898f440b86d2799 + herb (0.11.3-x86_64-linux-musl) sha256=af5634e0402d8e552bd5d0b332016852d34967d5d48aa9c432572608fe3070fe i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5 io-console (0.9.5) sha256=83dd9bbf4c4680416629245b39cd4212eb5f4d9a4ea91804870c1f6b846414d5 irb (1.19.0) sha256=55ee56acbdd6c9fe06a2e6909f46a24e5c41f45f16906bab04e8049cf46f1d27 diff --git a/gemfiles/rails_main_head.gemfile.lock b/gemfiles/rails_main_head.gemfile.lock index 6f290f7d8..c01885c89 100644 --- a/gemfiles/rails_main_head.gemfile.lock +++ b/gemfiles/rails_main_head.gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: dde4894f1af1121ea65e48d9abd5a8469d4b80e5 + revision: af32ebb8cb4ebf46fd70f6f2faeb30e0c1cbe998 branch: main specs: actioncable (8.2.0.alpha) @@ -163,9 +163,9 @@ GEM crass (1.0.9) cruise (0.3.0) csv (3.3.7) - cuprite (0.22) + cuprite (1.0) capybara (~> 3.0) - ferrum (~> 0.22.0) + ferrum (~> 1.0) date (3.6.0) diff-lcs (1.6.2) drb (2.2.3) @@ -179,20 +179,20 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ferrum (0.22.0) - addressable (~> 2.5) + ferrum (1.0.0) + addressable (~> 2.10) base64 (~> 0.2) - concurrent-ruby (~> 1.1) - websocket-driver (~> 0.7) + concurrent-ruby (~> 1.3, >= 1.3.7) + websocket-driver (~> 0.9, >= 0.9.1) ffi (1.17.4) - globalid (1.4.0) + globalid (1.5.0) activesupport (>= 6.1) haml (7.5.2) prism (>= 1.1.0) temple (>= 0.8.2) thor tilt - herb (0.11.2) + herb (0.11.3) i18n (1.15.2) concurrent-ruby (~> 1.0) io-console (0.9.5) diff --git a/performance/compare.rb b/performance/compare.rb index ff00ecc4a..93e310187 100755 --- a/performance/compare.rb +++ b/performance/compare.rb @@ -3,7 +3,10 @@ # Compares performance/measure.rb runs and fails when any scenario's # render, cold digest, boot, or development executor ratio regresses by -# more than THRESHOLD (default 0.05). +# more than THRESHOLD (default 0.05), or its absolute component time regresses +# by more than TIME_THRESHOLD (default 0.10). Ratios cancel out machine noise, +# while absolute times catch dependency changes that slow components and +# partials alike. # # ruby performance/compare.rb base.json head.json # ruby performance/compare.rb base/ head/ @@ -25,50 +28,94 @@ runs.first.merge( "scenarios" => runs.first["scenarios"].to_h do |name, scenario| ratios = runs.flat_map { |run| run.dig("scenarios", name, "ratios") || [] } - [name, scenario.merge("ratio" => median.call(ratios), "ratios" => ratios)] + times = runs.flat_map { |run| run.dig("scenarios", name, "component_times_ms") || [] } + scenario = scenario.merge("ratio" => median.call(ratios), "ratios" => ratios) + scenario = scenario.merge("component_ms" => median.call(times), "component_times_ms" => times) if times.any? + [name, scenario] end ) end threshold = Float(ENV.fetch("THRESHOLD", 0.05)) +time_threshold = Float(ENV.fetch("TIME_THRESHOLD", 0.10)) +percent = -> (value) { "#{(value * 100).round(1)}%" } puts("### ViewComponent performance (Rails #{head["rails"]}, #{head["ruby"].split.first(2).join(" ")})") puts puts( - "Ratios are component render time / equivalent partial render time; for `cold_digest`, cold component digest time / cold partial digest time; for `boot`, time spent in ViewComponent during boot / the rest of boot; and for `executor`, development executor time with ViewComponent / Rails alone. Lower is faster." + "Ratios are component render time / equivalent partial render time; for `cold_digest`, cold component digest time / cold partial digest time; for `boot`, time spent in ViewComponent during boot / the rest of boot; and for `executor`, development executor time with ViewComponent / Rails alone. Lower is faster. Times are median absolute component times, measured on the same runner." ) puts -puts("| Scenario | Base ratio | Head ratio | Change | Allocations (base → head) | |") -puts("| --- | ---: | ---: | ---: | ---: | --- |") +base_gems = base.fetch("gems", {}).except("view_component") +head_gems = head.fetch("gems", {}).except("view_component") +dependency_changes = (base_gems.keys | head_gems.keys).sort.filter_map do |name| + next if base_gems[name] == head_gems[name] -regressions = head["scenarios"].filter_map do |name, current| + "`#{name}` #{base_gems[name] || "—"} → #{head_gems[name] || "—"}" +end + +if dependency_changes.empty? + puts("Dependencies are unchanged.") +else + puts("Dependency changes: #{dependency_changes.join(", ")}.") +end + +puts +puts("| Scenario | Base ratio | Head ratio | Change | Time (base → head) | Change | Allocations (base → head) | |") +puts("| --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |") + +ratio_regressions = [] +time_regressions = [] +head["scenarios"].each do |name, current| previous = base["scenarios"][name] unless previous - puts("| #{name} | — | #{format("%.3f", current["ratio"])} | new | #{current["component_allocations"]} | |") + puts( + "| #{name} | — | #{format("%.3f", current["ratio"])} | new | — | | #{current["component_allocations"]} | |" + ) next end change = current["ratio"] / previous["ratio"] - 1 - regressed = current["ratio"] > previous["ratio"] * (1 + threshold) + ratio_regressions << name if change > threshold + + time = "—" + time_change = "" + if previous["component_ms"] && current["component_ms"] + time = format("%.3fms → %.3fms", previous["component_ms"], current["component_ms"]) + time_change = current["component_ms"] / previous["component_ms"] - 1 + time_regressions << name if time_change > time_threshold + time_change = format("%+.1f%%", time_change * 100) + end + puts( format( - "| %s | %.3f | %.3f | %+.1f%% | %d → %d | %s |", + "| %s | %.3f | %.3f | %+.1f%% | %s | %s | %d → %d | %s |", name, previous["ratio"], current["ratio"], change * 100, + time, + time_change, previous["component_allocations"], current["component_allocations"], - regressed ? "❌" : "✅" + (ratio_regressions.include?(name) || time_regressions.include?(name)) ? "❌" : "✅" ) ) - name if regressed end puts -if regressions.empty? - puts("No scenario regressed by more than #{(threshold * 100).round(1)}%.") +if ratio_regressions.empty? && time_regressions.empty? + puts( + "No ratio regressed by more than #{percent.call(threshold)} and no time by more than #{percent.call(time_threshold)}." + ) else - puts("Regressed by more than #{(threshold * 100).round(1)}%: #{regressions.join(", ")}.") + if ratio_regressions.any? + puts("Ratio regressed by more than #{percent.call(threshold)}: #{ratio_regressions.join(", ")}.") + end + + if time_regressions.any? + puts("Time regressed by more than #{percent.call(time_threshold)}: #{time_regressions.join(", ")}.") + end + exit(1) end diff --git a/performance/measure.rb b/performance/measure.rb index a4e9f9f1d..96ee90ed9 100755 --- a/performance/measure.rb +++ b/performance/measure.rb @@ -8,7 +8,8 @@ # bundle exec ruby performance/measure.rb [OUTPUT_JSON] # # Set VIEW_COMPONENT_LIB to the `lib` directory of another checkout to measure -# that version of ViewComponent with this checkout's dependencies and scenarios. +# that version of ViewComponent with this checkout's scenarios. Also set +# BUNDLE_GEMFILE to that checkout's Gemfile to use its dependencies. # PASSES (default 15), SAMPLE_SECONDS (default 0.1), and BOOT_COMPONENTS # (default 300) tune the run length. @@ -116,6 +117,7 @@ class BenchmarksController < ActionController::Base "iterations" => {"reference" => reference_iterations, "component" => scenario_iterations}, "reference_ms" => median.call(samples.map(&:first)) * 1000, "component_ms" => median.call(samples.map(&:last)) * 1000, + "component_times_ms" => samples.map { |_reference_time, scenario_time| scenario_time * 1000 }, "reference_allocations" => allocations.call(reference), "component_allocations" => allocations.call(scenario) } @@ -276,6 +278,7 @@ def initialize(name:) "ratios" => ratios, "reference_ms" => median.call(samples.map { |sample| sample["rest"]["seconds"] }) * 1000, "component_ms" => median.call(samples.map { |sample| sample["view_component"]["seconds"] }) * 1000, + "component_times_ms" => samples.map { |sample| sample["view_component"]["seconds"] * 1000 }, "reference_allocations" => median.call(samples.map { |sample| sample["rest"]["allocations"] }), "component_allocations" => median.call(samples.map { |sample| sample["view_component"]["allocations"] }) } @@ -314,6 +317,7 @@ def initialize(name:) "iterations" => {"reference" => reference_run["iterations"], "component" => component_run["iterations"]}, "reference_ms" => median.call(reference_samples.map { |sample| sample["seconds"] }) * 1000, "component_ms" => median.call(component_samples.map { |sample| sample["seconds"] }) * 1000, + "component_times_ms" => component_samples.map { |sample| sample["seconds"] * 1000 }, "reference_allocations" => median.call(reference_samples.map { |sample| sample["allocations"] }), "component_allocations" => median.call(component_samples.map { |sample| sample["allocations"] }) } @@ -336,6 +340,10 @@ def initialize(name:) "view_component" => ViewComponent::VERSION::STRING, "view_component_lib" => view_component_lib, "git_sha" => git_sha.empty? ? nil : git_sha, + "gems" => Gem.loaded_specs.sort.to_h { |name, spec| + revision = spec.source.revision if spec.respond_to?(:source) && spec.source.respond_to?(:revision) + [name, revision ? "#{spec.version} (#{revision[0, 12]})" : spec.version.to_s] + }, "passes" => passes, "scenarios" => results } diff --git a/test/script/benchmark_workflow_test.rb b/test/script/benchmark_workflow_test.rb index 444b16551..82ccc4096 100644 --- a/test/script/benchmark_workflow_test.rb +++ b/test/script/benchmark_workflow_test.rb @@ -70,13 +70,41 @@ def test_missing_release_tag_fails_instead_of_comparing_against_main refute(File.exist?(File.join(@directory, "output"))) end + def test_base_and_head_dependencies_are_installed_from_their_own_gemfiles + write("tmp/base/gemfiles/rails_8.1.gemfile", "") + write("tmp/head/gemfiles/rails_8.1.gemfile", "") + stdout, stderr, status = run_dependency_install + + assert(status.success?, "#{stdout}\n#{stderr}") + base_gemfile, head_gemfile = %w[base head].map { |side| + File.join(@directory, "tmp/#{side}/gemfiles/rails_8.1.gemfile") + } + assert_equal("BASE_BUNDLE_GEMFILE=#{base_gemfile}\nHEAD_BUNDLE_GEMFILE=#{head_gemfile}\n", read("env")) + [base_gemfile, head_gemfile].each do |gemfile| + assert_includes(read("commands.log"), "#{gemfile} install --jobs 4") + assert_includes(read("commands.log"), "#{gemfile} config set --local path #{@directory}/vendor/bundle") + end + end + + def test_base_without_the_gemfile_falls_back_to_head_dependencies + write("tmp/head/gemfiles/rails_8.1.gemfile", "") + stdout, stderr, status = run_dependency_install + + assert(status.success?, "#{stdout}\n#{stderr}") + assert_includes(stdout, "::warning::Base has no gemfiles/rails_8.1.gemfile") + assert_includes( + read("env"), + "BASE_BUNDLE_GEMFILE=#{File.join(@directory, "tmp/head/gemfiles/rails_8.1.gemfile")}\n" + ) + end + def test_successful_comparisons_are_saved_for_the_comment assert_comparison_report(head_ratio: 1.0, exitstatus: 0) end def test_regressions_still_fail_and_are_saved_for_the_comment assert_comparison_report(head_ratio: 2.0, exitstatus: 1) - assert_includes(read("tmp/performance/report.md"), "Regressed by more than 5.0%: component.") + assert_includes(read("tmp/performance/report.md"), "Ratio regressed by more than 5.0%: component.") end def test_comments_include_both_rails_results_and_are_updated_on_reruns @@ -204,6 +232,26 @@ def test_only_same_repository_release_prs_use_release_reporting private + def run_dependency_install + @environment["COMMAND_LOG"] = File.join(@directory, "commands.log") + mock_commands( + <<~BASH + bundle() { + printf '%s %s\\n' "$BUNDLE_GEMFILE" "$*" >> "$COMMAND_LOG" + } + BASH + ) + run_step( + "benchmark-rails", + "Install base and head dependencies", + env: { + "GITHUB_WORKSPACE" => @directory, + "GITHUB_ENV" => File.join(@directory, "env"), + "BUNDLE_GEMFILE" => "gemfiles/rails_8.1.gemfile" + } + ) + end + def assert_comparison_report(head_ratio:, exitstatus:) results = lambda do |ratio| JSON.generate( @@ -219,11 +267,11 @@ def assert_comparison_report(head_ratio:, exitstatus:) case "$3" in performance/measure.rb) mkdir -p "$(dirname "$4")" - if [ -n "${VIEW_COMPONENT_LIB:-}" ]; then - printf '%s\\n' "$BASE_RESULT" > "$4" - else - printf '%s\\n' "$HEAD_RESULT" > "$4" - fi + case "$VIEW_COMPONENT_LIB:$BUNDLE_GEMFILE" in + "tmp/base/lib:$BASE_BUNDLE_GEMFILE") printf '%s\\n' "$BASE_RESULT" > "$4" ;; + "tmp/head/lib:$HEAD_BUNDLE_GEMFILE") printf '%s\\n' "$HEAD_RESULT" > "$4" ;; + *) return 78 ;; + esac ;; performance/compare.rb) "$RUBY_EXECUTABLE" "$COMPARE_SCRIPT" "$4" "$5" ;; *) return 77 ;; @@ -238,6 +286,8 @@ def assert_comparison_report(head_ratio:, exitstatus:) env: { "BASE_RESULT" => results.call(1.0), "HEAD_RESULT" => results.call(head_ratio), + "BASE_BUNDLE_GEMFILE" => "/base/gemfiles/rails_8.1.gemfile", + "HEAD_BUNDLE_GEMFILE" => "/head/gemfiles/rails_8.1.gemfile", "RUBY_EXECUTABLE" => RbConfig.ruby, "COMPARE_SCRIPT" => File.join(ROOT, "performance/compare.rb"), "BASE_REF" => "v4.21.0", @@ -246,7 +296,7 @@ def assert_comparison_report(head_ratio:, exitstatus:) ) assert_equal(exitstatus, status.exitstatus, "#{stdout}\n#{stderr}") - assert_equal(6, Dir[File.join(@directory, "tmp/performance/{base,head}/*.json")].size) + assert_equal(12, Dir[File.join(@directory, "tmp/performance/{base,head}/*.json")].size) assert_equal(read("summary.md"), read("tmp/performance/report.md")) assert_includes(read("tmp/performance/report.md"), "Base: `v4.21.0`; head: `merge-sha`") assert_includes(read("tmp/performance/report.md"), "| Scenario | Base ratio | Head ratio |") @@ -312,8 +362,9 @@ def step(job, name) def run_step(job, name, env: {}) configuration = step(job, name) + step_env = configuration.fetch("env", {}).to_h { |key, value| [key, value.to_s] } Open3.capture3( - @environment.merge(env), + @environment.merge(step_env.reject { |_key, value| value.include?("${{") }, env), "bash", "-e", "-o", diff --git a/test/script/performance_test.rb b/test/script/performance_test.rb index 872e441ce..2281b7379 100644 --- a/test/script/performance_test.rb +++ b/test/script/performance_test.rb @@ -2,6 +2,7 @@ require "minitest/autorun" require "json" +require "fileutils" require "open3" require "tmpdir" @@ -25,6 +26,8 @@ def test_measures_rendering_cold_digests_boot_and_executor assert(status.success?, "#{stdout}\n#{stderr}") results = JSON.parse(File.read(output)) + rails_version = Regexp.escape(Gem.loaded_specs.fetch("rails").version.to_s) + assert_match(/\A#{rails_version}( \(\h{12}\))?\z/, results.dig("gems", "rails")) assert_equal( %w[component inline_call inline_erb_template slots collection cold_digest boot executor], results["scenarios"].keys @@ -32,6 +35,7 @@ def test_measures_rendering_cold_digests_boot_and_executor results["scenarios"].each_value do |scenario| assert_equal(1, scenario["ratios"].size) assert_equal(scenario["ratios"].first, scenario["ratio"]) + assert_equal([scenario["component_ms"]], scenario["component_times_ms"]) %w[reference_ms component_ms reference_allocations component_allocations].each do |key| assert_operator(scenario[key], :>, 0) end @@ -39,6 +43,74 @@ def test_measures_rendering_cold_digests_boot_and_executor end end + def test_comparison_reports_dependency_changes + Dir.mktmpdir do |directory| + results = lambda do |gems| + { + "rails" => "8.1", + "ruby" => RUBY_DESCRIPTION, + "gems" => gems, + "scenarios" => {"component" => {"ratio" => 1.0, "ratios" => [1.0], "component_allocations" => 100}} + } + end + + base = File.join(directory, "base.json") + head = File.join(directory, "head.json") + File.write(base, JSON.generate(results.call("rails" => "8.1.0", "old" => "1.0", "view_component" => "4.0.0"))) + File.write(head, JSON.generate(results.call("rails" => "8.1.1", "new" => "2.0", "view_component" => "4.1.0"))) + + stdout, stderr, status = Open3.capture3(RbConfig.ruby, File.join(ROOT, "performance/compare.rb"), base, head) + + assert(status.success?, "#{stdout}\n#{stderr}") + assert_includes(stdout, "Dependency changes: `new` — → 2.0, `old` 1.0 → —, `rails` 8.1.0 → 8.1.1.") + + File.write(head, File.read(base)) + stdout, = Open3.capture3(RbConfig.ruby, File.join(ROOT, "performance/compare.rb"), base, head) + assert_includes(stdout, "Dependencies are unchanged.") + end + end + + def test_comparison_rejects_absolute_time_regressions_with_unchanged_ratios + Dir.mktmpdir do |directory| + results = lambda do |times| + { + "rails" => "8.1", + "ruby" => RUBY_DESCRIPTION, + "scenarios" => { + "component" => { + "ratio" => 1.0, + "ratios" => [1.0], + "component_times_ms" => times, + "component_allocations" => 100 + } + } + } + end + + FileUtils.mkdir_p(File.join(directory, "base")) + FileUtils.mkdir_p(File.join(directory, "head")) + File.write(File.join(directory, "base/1.json"), JSON.generate(results.call([1.0, 9.0]))) + File.write(File.join(directory, "base/2.json"), JSON.generate(results.call([1.0]))) + File.write(File.join(directory, "head/1.json"), JSON.generate(results.call([1.2, 1.2, 1.0]))) + + stdout, stderr, status = Open3.capture3( + {"THRESHOLD" => "0.05", "TIME_THRESHOLD" => "0.1"}, + RbConfig.ruby, + File.join(ROOT, "performance/compare.rb"), + File.join(directory, "base"), + File.join(directory, "head") + ) + + assert_equal(1, status.exitstatus, "#{stdout}\n#{stderr}") + assert_includes( + stdout, + "| component | 1.000 | 1.000 | +0.0% | 1.000ms → 1.200ms | +20.0% | 100 → 100 | ❌ |" + ) + assert_includes(stdout, "Time regressed by more than 10.0%: component.") + refute_includes(stdout, "Ratio regressed") + end + end + def test_comparison_rejects_cold_digest_boot_and_executor_regressions Dir.mktmpdir do |directory| base = File.join(directory, "base.json") @@ -68,7 +140,7 @@ def test_comparison_rejects_cold_digest_boot_and_executor_regressions head ) assert_equal(1, status.exitstatus, "#{stdout}\n#{stderr}") - assert_includes(stdout, "Regressed by more than 5.0%: #{name}.") + assert_includes(stdout, "Ratio regressed by more than 5.0%: #{name}.") end end end