rusackas opened a new pull request, #42511:
URL: https://github.com/apache/superset/pull/42511

   ### SUMMARY
   Superset's frontend bundle size is a recurring complaint (per an internal 
audit of CI speedup opportunities), but there's been no ongoing visibility into 
it -- only periodic manual cleanup. This turns it into a ratchet: track it 
continuously, comment on PRs that regress it.
   
   Adds a `bundle-size` job to `superset-frontend.yml` alongside the existing 
`lint-frontend`/`validate-frontend`/etc. jobs. It:
   1. Reuses the already-built CI Docker image (same one every sibling job 
downloads -- no extra image build)
   2. Runs the real production build (`npm run build`) inside it
   3. Reduces the resulting webpack stats down to a few headline per-entrypoint 
sizes (`scripts/bundle-size-summary.js`)
   4. Tracks them over time via 
[benchmark-action/github-action-benchmark](https://github.com/benchmark-action/github-action-benchmark),
 posting a PR comment when a change regresses past 110% of the last recorded 
baseline
   
   **Cost:** the only new work is the production webpack build itself, and it's 
cheap after the first run. webpack's persistent filesystem cache (already 
configured in `webpack.config.js`) makes warm rebuilds ~20s locally vs. several 
minutes cold -- confirmed by hand against this repo's actual build, both cold 
(after touching `webpack.config.js`, which invalidates the cache) and warm. The 
job is gated the same way as its siblings 
(`needs.frontend-build.outputs.should-run == 'true'`), so it's skipped entirely 
on non-frontend PRs.
   
   **Why `webpack.config.js` needed a change:** the default `stats: 'minimal'` 
omits per-asset sizes entirely from `--json` output. The alternative, 
`--stats=normal`, includes them but also serializes the full ~15k-module 
dependency graph -- a 560+MB `stats.json` for this app, large enough that a 
plain `fs.readFileSync` throws `ERR_STRING_TOO_LONG` (verified this failure 
mode directly). Added a `BUNDLE_SIZE_STATS` env-gated override requesting just 
`{ assets: true, entrypoints: true }` -- mirrors the existing `BUNDLE_ANALYZER` 
env-gated pattern already in this file. Verified the resulting schema 
end-to-end against both a minimal synthetic webpack project and real stats 
pulled from this repo's actual production build (`spa` entrypoint = ~8.25MB, 
`embedded` = ~7.9MB, for reference).
   
   **Why not the usual `gh-pages` storage:** benchmark-action's default is to 
commit history to a `gh-pages` branch. `apache/superset`'s `gh-pages` branch is 
already live production infrastructure -- the Helm chart index published by 
`superset-helm-release.yml` (confirmed via its recent commit history) -- not 
free real estate, and I didn't want this to risk stomping on it. Instead this 
uses `external-data-json-path` with `actions/cache`: restored on every run (PR 
or push) so PRs get a same-baseline comparison and regression comment, but only 
saved back to the cache on push to `master`, so an unmerged PR's numbers 
(including ones that regress on purpose to test something) never become the 
shared baseline. No git branch is touched by any code path here, and no 
PAT/GitHub App is needed -- `comment-on-alert` only needs the default per-job 
`GITHUB_TOKEN` (`contents: write` + `pull-requests: write`, scoped to this one 
job, auto-revoked at job end).
   
   ### TESTING INSTRUCTIONS
   - `pre-commit run` (prettier, oxlint, frontend type-checking, `zizmor` GHA 
security audit) passes on all three touched files.
   - Verified the webpack stats schema and the reducer script end-to-end 
locally: a minimal synthetic webpack project using the same 
`BUNDLE_SIZE_STATS`-gated stats override produces the exact 
`entrypoints.<name>.assets: [{name, size}]` shape the reducer expects, and the 
reducer correctly extracts JS/CSS sizes per tracked entrypoint.
   - Ran a real production build of this repo locally (`BUNDLE_SIZE_STATS=true 
npm run build -- --json=stats.json`) to confirm it completes with 0 errors and 
to pull real entrypoint sizes for sanity-checking the numbers above.
   - CI on this PR is the live end-to-end test: the `bundle-size` job should 
run, and its job summary should show a size comparison table.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to