From effdcd704bff8e87b01e31cbed33bf38c1943ec9 Mon Sep 17 00:00:00 2001 From: atharva9167j Date: Sun, 6 Sep 2026 16:18:47 +0530 Subject: [PATCH 1/2] perf(build): reduce package size and optimize V8 heap memory footprint - Exclude dead-weight `node_modules` from `app.asar` packaging: all frontend and electron main process modules are already bundled into `dist/` and `dist-electron/` by Vite, saving ~238 MB of redundant files. - Deduplicate assets in `electron-builder.json5`: exclude `wallpapers/`, `cursors/`, and `mediapipe/` from `app.asar` as they are already provisioned via `extraResources` for raw filesystem access by the native compositor, saving ~17 MB. - Exclude documentation assets (`demo.gif`, `preview*.png`) from `app.asar` packaging (~8 MB saved). - Exclude unused `ffmpeg-shared.exe` from Windows `extraResources`. - Restrict `electronLanguages` to the 13 supported locales, removing 42 unneeded Chromium locale `.pak` files (~20 MB saved). - Set `compression: "maximum"` in `electron-builder.json5` to enable solid LZMA2 compression for Windows installers and release archives. - Add `--optimize-for-size` V8 engine flag in `electron/main.ts` to reduce heap footprint across renderer and background processes. --- electron-builder.json5 | 30 ++++++++++++++++++++++++++++-- electron/main.ts | 3 +++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/electron-builder.json5 b/electron-builder.json5 index dafe8c690..e874060ea 100644 --- a/electron-builder.json5 +++ b/electron-builder.json5 @@ -58,7 +58,23 @@ // needs a system libvips we don't provide and breaks on CI/local ("vips-cpp.42 not found"), so we // let electron-builder use the prebuilt instead of recompiling. "buildDependenciesFromSource": false, - "compression": "normal", + "compression": "maximum", + // Strip unused Chromium locale pak files (saves ~20 MB). Only package locales supported by OpenScreen. + "electronLanguages": [ + "en-US", + "fr", + "ar", + "es", + "it", + "ja", + "ko", + "pt-BR", + "ru", + "tr", + "vi", + "zh-CN", + "zh-TW" + ], "directories": { "output": "release/${version}", // Electron-builder's default, spelled out because the appx target depends on it: @@ -72,6 +88,16 @@ "files": [ "dist", "dist-electron", + // Exclude documentation assets that Vite copied from public/ (saves ~8 MB) + "!dist/demo.gif", + "!dist/preview*.png", + // Exclude assets already bundled into extraResources (saves ~17 MB duplicate in asar) + "!dist/wallpapers/**", + "!dist/cursors/**", + "!dist/mediapipe/**", + // Exclude dead-weight node_modules: all frontend and electron code is pre-bundled by Vite (saves ~238 MB) + "!node_modules/**", + "!**/node_modules/**", "!*.png", "!preview*.png", "!*.md", @@ -369,7 +395,7 @@ // in the app spawns. Shipping it added a large binary to every Windows // installer, plus an LGPL redistribution obligation, for a file no // shipped code opens. - "filter": ["win32-*/*", "!win32-*/ffmpeg.exe"] + "filter": ["win32-*/*", "!win32-*/ffmpeg.exe", "!win32-*/ffmpeg-shared.exe"] } ], // The D3D11 compositor addon deliberately does NOT travel through `files` into diff --git a/electron/main.ts b/electron/main.ts index ec961aead..f9840840c 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -76,6 +76,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); // HUD/tray/menu. Parsed before any GUI side effects; see electron/cli/. const cliCommand = parseCliArgs(process.argv, app.isPackaged ? 1 : 2); +// Optimize V8 heap allocation to reduce memory footprint across processes. +app.commandLine.appendSwitch("js-flags", "--optimize-for-size"); + // Use Screen & System Audio Recording permissions instead of the CoreAudio Tap API on macOS. // Tap needs NSAudioCaptureUsageDescription in the parent app's Info.plist, which breaks when // running from a terminal/IDE during dev. From c098a1e7558bde18fb7e9524af2c716695200e32 Mon Sep 17 00:00:00 2001 From: atharva9167j Date: Mon, 7 Sep 2026 00:31:42 +0530 Subject: [PATCH 2/2] fix: update mediapipe notice path and clarify renderer v8 flag scope --- THIRD-PARTY-NOTICES.md | 2 +- electron/main.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/THIRD-PARTY-NOTICES.md b/THIRD-PARTY-NOTICES.md index 6bfe88fb4..d53cfc019 100644 --- a/THIRD-PARTY-NOTICES.md +++ b/THIRD-PARTY-NOTICES.md @@ -71,7 +71,7 @@ distributed by their own registries, not redistributed inside our binaries. - **Components**: `selfie_segmentation.tflite`, `selfie_segmentation_landscape.tflite` and the `selfie_segmentation_landscape.onnx` - derived from them, shipped inside `app.asar` under `dist/mediapipe/`. + derived from them, shipped under `resources/mediapipe/`. - **License**: Apache-2.0 — . Copyright The MediaPipe Authors. - The `.onnx` is a **derived work**, generated from the vendored `.tflite` by diff --git a/electron/main.ts b/electron/main.ts index f9840840c..88703f7bd 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -76,7 +76,9 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url)); // HUD/tray/menu. Parsed before any GUI side effects; see electron/cli/. const cliCommand = parseCliArgs(process.argv, app.isPackaged ? 1 : 2); -// Optimize V8 heap allocation to reduce memory footprint across processes. +// Optimize V8 heap allocation to reduce memory footprint across renderer processes. +// Note: app.commandLine.appendSwitch('js-flags') does not affect the main process V8 isolate, +// which is already initialized before main.ts executes. app.commandLine.appendSwitch("js-flags", "--optimize-for-size"); // Use Screen & System Audio Recording permissions instead of the CoreAudio Tap API on macOS.