From 5e93bb018920dffa80f19554fdb2825446e6f705 Mon Sep 17 00:00:00 2001 From: "Joshua A. Horton" Date: Wed, 31 May 2023 15:51:50 +0700 Subject: [PATCH] feat(web): writes profile logs to file, outputs within new /web/build/profiling folder --- common/web/lm-worker/build-bundler.js | 29 ++++++++++++++++----------- web/src/app/browser/build-bundler.js | 9 +++++++-- web/src/app/browser/build.sh | 5 +++++ 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/common/web/lm-worker/build-bundler.js b/common/web/lm-worker/build-bundler.js index 599bd4585a..a1ec363cd9 100644 --- a/common/web/lm-worker/build-bundler.js +++ b/common/web/lm-worker/build-bundler.js @@ -109,19 +109,24 @@ const embeddedWorkerBuildOptions = { // Direct-use version await esbuild.build(embeddedWorkerBuildOptions); +// We want a specialized bundle build here instead; no output, but minified like +// the actual release worker. +const minifiedProfilingOptions = { + ...embeddedWorkerBuildOptions, + minify: true, + metafile: true, + write: false // don't actually write the file. +} + +let result = await esbuild.build(minifiedProfilingOptions); +let filesizeProfile = await esbuild.analyzeMetafile(result.metafile, { verbose: true }); +fs.writeFileSync('build/filesize-profile.log', ` +// Minified Worker filesize profile, before polyfilling +${filesizeProfile} +`); + if(EMIT_FILESIZE_PROFILE) { - // We want a specialized bundle build here instead; no output, but minified like - // the actual worker. - const minifiedProfilingOptions = { - ...embeddedWorkerBuildOptions, - minify: true, - metafile: true, - write: false // don't actually write the file. - } - - let result = await esbuild.build(minifiedProfilingOptions); - console.log("Minified, pre-polyfill worker filesize profile:"); // Profiles the sourcecode! - console.log(await esbuild.analyzeMetafile(result.metafile, { verbose: true })); + console.log(filesizeProfile); } diff --git a/web/src/app/browser/build-bundler.js b/web/src/app/browser/build-bundler.js index 19236a44e0..17a495e02a 100644 --- a/web/src/app/browser/build-bundler.js +++ b/web/src/app/browser/build-bundler.js @@ -82,12 +82,17 @@ let result = await esbuild.build({ treeShaking: true, tsconfig: './tsconfig.json', // Enables source-file output size profiling! - metafile: EMIT_FILESIZE_PROFILE + metafile: true }); +let filesizeProfile = await esbuild.analyzeMetafile(result.metafile, { verbose: true }); +fs.writeFileSync('../../../build/app/browser/filesize-profile.log', ` +// Minified Keyman Engine for Web ('app/browser' target), filesize profile +${filesizeProfile} +`); if(EMIT_FILESIZE_PROFILE) { // Profiles the sourcecode! - console.log(await esbuild.analyzeMetafile(result.metafile, { verbose: true })); + console.log(filesizeProfile); } await esbuild.build({ diff --git a/web/src/app/browser/build.sh b/web/src/app/browser/build.sh index 63c24f2df8..2cbc51fae5 100755 --- a/web/src/app/browser/build.sh +++ b/web/src/app/browser/build.sh @@ -52,6 +52,11 @@ compile_and_copy() { # Update the build/publish copy of our build artifacts prepare + + local PROFILE_DEST="$KEYMAN_ROOT/web/build/profiling/" + mkdir -p "$PROFILE_DEST" + cp "$KEYMAN_ROOT/web/build/app/browser/filesize-profile.log" "$PROFILE_DEST/web-engine-filesize.log" + cp "$KEYMAN_ROOT/common/web/lm-worker/build/filesize-profile.log" "$PROFILE_DEST/lm-worker-filesize.log" } builder_run_action configure verify_npm_setup