Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Replace bundle size reporter filter #38979

Merged
merged 6 commits into from Apr 12, 2024
Merged

[core] Replace bundle size reporter filter #38979

merged 6 commits into from Apr 12, 2024

Conversation

Janpot
Copy link
Member

@Janpot Janpot commented Sep 14, 2023

Making sure we include everything that is not looking like a package subpath export.

This is meant to solve https://www.notion.so/mui-org/code-infra-Investigate-broken-bundle-size-tracker-7260ba7718644642ba781d346c533579. See in #33015 (comment) how <Hidden> size significantly changed but wasn't reported. We need per-module bundle size tracking, per npm package size isn't enough.

@Janpot Janpot added the core Infrastructure work going on behind the scenes label Sep 14, 2023
@mui-bot
Copy link

mui-bot commented Sep 14, 2023

Netlify deploy preview

https://deploy-preview-38979--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 9395efd

@Janpot Janpot marked this pull request as ready for review September 14, 2023 14:10
@oliviertassinari oliviertassinari changed the title Replace bundle size reporter filter [core] Replace bundle size reporter filter Sep 14, 2023
dangerfile.ts Outdated
@@ -62,7 +62,7 @@ function createComparisonFilter(parsedThreshold: number, gzipThreshold: number)
*/
function isPackageComparison(comparisonEntry: [string, any]) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this filter in the first place? It feels like

Suggested change
function isPackageComparison(comparisonEntry: [string, any]) {

could do the job.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we need this filter in the first place?

As far as I'm concerned, that's up to the core team to decide 🙂. I'm fine with either way.

Copy link
Member

Choose a reason for hiding this comment

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

I imagine the main downside is about the number of diffs it could create. We could workaround it, say:

diff --git a/dangerfile.ts b/dangerfile.ts
index bd769f141a..aedc4d72d7 100644
--- a/dangerfile.ts
+++ b/dangerfile.ts
@@ -55,16 +55,6 @@ function createComparisonFilter(parsedThreshold: number, gzipThreshold: number)
   };
 }

-/**
- * Checks if the bundle is of a package e.b. `@mui/material` but not
- * `@mui/material/Paper`.
- * @param {[string, any]} comparisonEntry
- */
-function isPackageComparison(comparisonEntry: [string, any]) {
-  const [bundleKey] = comparisonEntry;
-  return !/^@[\w-]+\/[\w-]+\/.+$/.test(bundleKey);
-}
-
 /**
  * Generates a user-readable string from a percentage change.
  * @param {number} change
@@ -160,12 +150,23 @@ async function reportBundleSize() {
   if (anyResultsChanges.length > 0) {
     const importantChanges = mainResults
       .filter(createComparisonFilter(parsedSizeChangeThreshold, gzipSizeChangeThreshold))
-      .filter(isPackageComparison)
+      .sort(([, a], [, b]) => {
+        const aDiff = Math.abs(a.parsed.absoluteDiff) + Math.abs(a.gzip.absoluteDiff);
+        const bDiff = Math.abs(b.parsed.absoluteDiff) + Math.abs(b.gzip.absoluteDiff);
+        return bDiff - aDiff;
+      })
       .map(generateEmphasizedChange);

     // have to guard against empty strings
     if (importantChanges.length > 0) {
-      markdown(importantChanges.join('\n'));
+      let text = importantChanges.slice(0, 9).join('\n');
+
+      if (importantChanges.length > 10) {
+        text += '\n';
+        text += `and ${importantChanges.length - 10} more changes`;
+      }
+
+      markdown(text);
     }

     const details = `## Bundle size report

Copy link
Member Author

@Janpot Janpot Sep 20, 2023

Choose a reason for hiding this comment

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

Tweaked the implementation a bit (the slice is off by one 🙂) and added to this PR. Also defaulted to 20 items, because why not?

@Janpot Janpot changed the base branch from master to next March 21, 2024 11:04
@Janpot Janpot requested a review from a team April 5, 2024 16:10
@Janpot Janpot merged commit db8d725 into mui:next Apr 12, 2024
19 checks passed
@Janpot Janpot deleted the danger branch April 12, 2024 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes performance test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants