Skip to content

Commit

Permalink
Stable bundle size by disabling mangle cache (#37043)
Browse files Browse the repository at this point in the history
* Stable bundle size by disabling mangle cache

The mangle cache is necessary when generating multiple binaries which need to interact. However, our bundle size workflow doesn't actually run the code, it just needs to estimate the size impact a PR causes.

Hopefully fixes #37014.

* Update build-system/tasks/dist.js

Co-authored-by: Jake Fried <samouri@users.noreply.github.com>

Co-authored-by: Jake Fried <samouri@users.noreply.github.com>
  • Loading branch information
jridgewell and samouri committed Nov 24, 2021
1 parent 31cf6fd commit 4345078
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion build-system/pr-check/bundle-size-module-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const jobName = 'bundle-size-module-build.js';
* Steps to run during push builds.
*/
function pushBuildWorkflow() {
timedExecOrDie('amp dist --noconfig --esm --version_override 0000000000000');
timedExecOrDie(
'amp dist --noconfig --esm --version_override 0000000000000 --nomanglecache'
);
storeModuleBuildToWorkspace();
}

Expand Down
4 changes: 3 additions & 1 deletion build-system/pr-check/bundle-size-nomodule-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const jobName = 'bundle-size-nomodule-build.js';
* Steps to run during push builds.
*/
function pushBuildWorkflow() {
timedExecOrDie('amp dist --noconfig --version_override 0000000000000');
timedExecOrDie(
'amp dist --noconfig --version_override 0000000000000 --nomanglecache'
);
storeNomoduleBuildToWorkspace();
}

Expand Down
2 changes: 2 additions & 0 deletions build-system/tasks/dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ dist.flags = {
'Output code with whitespace (useful while profiling / debugging production code)',
fortesting: 'Compile production binaries for local testing',
noconfig: 'Compile production binaries without applying AMP_CONFIG',
nomanglecache:
'Do not share the mangle cache between binaries, useful only in estimating size impacts of code changes.',
config: 'Set the runtime\'s AMP_CONFIG to one of "prod" or "canary"',
coverage: 'Instrument code for collecting coverage information',
extensions: 'Build only the listed extensions',
Expand Down
6 changes: 3 additions & 3 deletions build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ const nameCache = {};
const mangleIdentifier = {
get(num) {
const charset =
'$ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz0123456789';
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789';
let base = 54;
let id = '';
do {
Expand Down Expand Up @@ -578,13 +578,13 @@ async function minify(code, map) {
sourceMap: {content: map},
toplevel: true,
module: !!argv.esm,
nameCache,
nameCache: argv.nomanglecache ? undefined : nameCache,
};
/* eslint-enable local/camelcase */

// Remove the local variable name cache which should not be reused between binaries.
// See https://github.com/ampproject/amphtml/issues/36476
/** @type {any}*/ (nameCache).vars = {};
nameCache.vars = undefined;

const minified = await terser.minify(code, terserOptions);
return {code: minified.code ?? '', map: minified.map};
Expand Down

0 comments on commit 4345078

Please sign in to comment.