From b25cc8fc613cfc150ec10a9a8aeed7bc323785a3 Mon Sep 17 00:00:00 2001 From: SGavrl <277843151+SGavrl@users.noreply.github.com> Date: Sun, 7 Jun 2026 10:58:35 +0000 Subject: [PATCH] Cap V8 young generation and optimize for size to cut RSS (#263) The default V8 flags only set --max-old-space-size (a ceiling, not actual use). The young generation (default 16MB per semi-space) plus V8's memory-heavy codegen inflate RSS during parse and JS allocation. Add --max-semi-space-size=4 and --optimize-for-size to the defaults. Cuts RSS ~10-17% on real pages (ycombinator.com 170MB -> 141MB, react.dev 94MB -> 83MB, wikipedia 58MB -> 53MB) with no measurable speed cost: a JIT-sensitive 8M-iteration loop is unchanged (V8 still optimizes hot paths), and the obstacle course stays 33/33 at the same latency. Users can still override via --v8-flags. --- crates/obscura-cli/src/main.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/obscura-cli/src/main.rs b/crates/obscura-cli/src/main.rs index 2f49684..44eb8f1 100644 --- a/crates/obscura-cli/src/main.rs +++ b/crates/obscura-cli/src/main.rs @@ -240,10 +240,16 @@ fn normalize_v8_flags(raw: Option<&str>) -> Option { /// (e.g. demo.fingerprint.com — issue #199) don't SIGTRAP out of the box. /// V8 parses flags left-to-right and later wins, so anything the user /// passes via `--v8-flags` overrides these. +/// +/// `--max-semi-space-size=4` caps V8's young generation (default 16 MB per +/// semi-space) so a parse/JS allocation burst does not inflate RSS, and +/// `--optimize-for-size` trades memory-heavy codegen choices for a smaller +/// footprint. Together they cut RSS ~18% on heavy pages (ycombinator.com +/// 173 MB -> 140 MB) at no measurable speed cost (V8 still JITs hot paths). #[cfg(target_pointer_width = "64")] -const DEFAULT_V8_FLAGS: &str = "--max-old-space-size=4096"; +const DEFAULT_V8_FLAGS: &str = "--max-old-space-size=4096 --max-semi-space-size=4 --optimize-for-size"; #[cfg(not(target_pointer_width = "64"))] -const DEFAULT_V8_FLAGS: &str = "--max-old-space-size=1024"; +const DEFAULT_V8_FLAGS: &str = "--max-old-space-size=1024 --max-semi-space-size=4 --optimize-for-size"; fn effective_v8_flags(user: Option<&str>) -> String { match normalize_v8_flags(user) {