Files
Netcatty/electron/preloadPath.cjs
T
陈大猫 52dfe7b524 perf(memory): implement Phase 1–2 idle, window, and terminal memory optimizations
- Fix kittyKeyboardBroadcast closure leak while preserving hibernated broadcast via detached top-level handler
- Replace dense KeywordHighlighter line caches with sparse packed triples and 53-bit numeric fingerprints
- Deduplicate hibernation snapshots and compress large scrollbacks via native gzip
- Eliminate cold-start terminalWorker wakes (portForwarding, transfer concurrency, empty monitor updates, cold MCP cancel, and stateless local shell/path queries)
- Auto-destroy hidden Settings and Tray windows after a configurable 20s idle grace window
- Tune Electron V8/GPU startup flags, switch V8 cache to code, and stream large app:// assets
- Split renderer entry bundle (App, NotesManager, MonitorPanels, globalAgentToolSpecs) and enable Chromium sandbox: true on all BrowserWindows via esbuild-bundled preload and IPC upload staging
- Add MRU=1 hidden WebGL context budget, dynamic main-window backgroundThrottling, bounded SSH/Fig caches, and lazy native addon loading
2026-11-27 08:28:48 +00:00

50 lines
1.5 KiB
JavaScript

"use strict";
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const PRELOAD_BUNDLE_FILENAME = "preload.bundle.cjs";
const PRELOAD_SOURCE_FILENAME = "preload.cjs";
function isBundledPreloadPath(preloadPath) {
return (
typeof preloadPath === "string"
&& path.basename(preloadPath) === PRELOAD_BUNDLE_FILENAME
);
}
/**
* Prefer the single-file esbuild preload bundle (which runs with sandbox: true).
* Fall back to the multi-file source preload.cjs if the bundle has not been
* generated yet (e.g., direct source execution or unit test fixtures).
*/
function resolvePreloadPath(electronDir = __dirname) {
const bundled = path.join(electronDir, PRELOAD_BUNDLE_FILENAME);
if (fs.existsSync(bundled)) {
return bundled;
}
return path.join(electronDir, PRELOAD_SOURCE_FILENAME);
}
/**
* Derive sandbox and additionalArguments for a BrowserWindow webPreferences
* block. Bundled preload requires zero Node.js runtime in the renderer process,
* saving ~10-14 MiB Private_Dirty per window while keeping getWindowsPtyInfo()
* working via `--netcatty-os-release=...`.
*/
function resolvePreloadWebPreferences(preloadPath) {
return {
sandbox: isBundledPreloadPath(preloadPath),
additionalArguments: [`--netcatty-os-release=${os.release()}`],
};
}
module.exports = {
PRELOAD_BUNDLE_FILENAME,
PRELOAD_SOURCE_FILENAME,
isBundledPreloadPath,
resolvePreloadPath,
resolvePreloadWebPreferences,
};