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.
This commit is contained in:
SGavrl authored and GitHub committed 2026-06-07 12:58:35 +02:00
1 parent 3fdf0a0be4
commit b25cc8fc61
1 file changed
+8 -2
+8 -2
View File
@@ -240,10 +240,16 @@ fn normalize_v8_flags(raw: Option<&str>) -> Option<String> {
/// (e.g. demo.fingerprint.com — issue #199) don't SIGTRAP out of the box. /// (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 /// V8 parses flags left-to-right and later wins, so anything the user
/// passes via `--v8-flags` overrides these. /// 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")] #[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"))] #[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 { fn effective_v8_flags(user: Option<&str>) -> String {
match normalize_v8_flags(user) { match normalize_v8_flags(user) {