Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

perf(v8): use pointer-compressed PartitionAlloc where available

ldm0eb59de736471
diff --git a/docs/RELEASING.md b/docs/RELEASING.md
index 40123e6d5..7fb08391c 100644
--- a/docs/RELEASING.md
+++ b/docs/RELEASING.md
@@ -27,9 +27,10 @@ only a staging copy, leaving the binary under `target/release` unchanged for
debugging. Because stripping invalidates a Mach-O signature, macOS staging
binaries are ad-hoc signed again and verified before packaging. They are not
Developer ID signed or notarized. Windows executables are not Authenticode
-signed. The allocator behind the default `jemalloc` feature is target-gated
-out on Windows, so Windows builds use the system allocator because upstream
-treats the Windows/MSVC combination as untested.
+signed. Linux x86_64 and both macOS targets use the allocator shim bundled in
+their official pointer-compressed V8 archives, routing native allocations to
+PartitionAlloc. Targets without such an archive retain their existing
+allocator: Linux ARM64 uses jemalloc and Windows uses the system allocator.
Release builds use one code-generation unit. The release workflow and the CI
release-regression binaries both invoke Cargo with `--release`, so they consume
diff --git a/moli-renderer-v8/Cargo.toml b/moli-renderer-v8/Cargo.toml
index cfbe5d384..c5cc1b1cb 100644
--- a/moli-renderer-v8/Cargo.toml
+++ b/moli-renderer-v8/Cargo.toml
@@ -91,7 +91,6 @@ indexmap = "2.6"
parking_lot = "0.12"
markup5ever = "0.39.0"
xml5ever = "0.39.0"
-v8 = "146.8.0"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.145"
serde_v8 = "=0.302.0"
@@ -106,6 +105,16 @@ xmlparser = "0.13.6"
typed-num = { version = "0.3.0", default-features = false, features = ["serde"] }
wasm_dep_analyzer = { git = "https://github.com/ldm0/wasm_dep_analyzer", branch = "moli0" }
+# rusty_v8 publishes pointer-compressed archives for these targets. Those
+# archives also provide the process-wide PartitionAlloc allocator shim.
+[target.'cfg(any(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"), all(target_os = "macos", any(target_arch = "x86_64", target_arch = "aarch64"))))'.dependencies]
+v8 = { version = "146.8.0", features = ["v8_enable_pointer_compression"] }
+
+# Keep the upstream V8 configuration on targets without an official
+# pointer-compressed archive.
+[target.'cfg(not(any(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"), all(target_os = "macos", any(target_arch = "x86_64", target_arch = "aarch64")))))'.dependencies]
+v8 = "146.8.0"
+
[dev-dependencies]
moli-fetch = { path = "../moli-fetch", features = ["test-support"] }
moli-parser = { path = "../moli-parser", features = ["test-support"] }
diff --git a/moli/Cargo.toml b/moli/Cargo.toml
index 1d3e4da95..540896bf0 100644
--- a/moli/Cargo.toml
+++ b/moli/Cargo.toml
@@ -34,7 +34,9 @@ tracing = "0.1.41"
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "fmt"] }
url = "2.5.7"
-[target.'cfg(not(target_os = "windows"))'.dependencies]
+# Keep the existing jemalloc fallback only where rusty_v8 does not publish a
+# pointer-compressed PartitionAlloc archive. Windows keeps its system allocator.
+[target.'cfg(all(not(target_os = "windows"), not(any(all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"), all(target_os = "macos", any(target_arch = "x86_64", target_arch = "aarch64"))))))'.dependencies]
tikv-jemalloc-sys = { version = "0.7.1", optional = true, default-features = false }
tikv-jemallocator = { version = "0.7.0", optional = true, default-features = false, features = ["override_allocator_on_supported_platforms"] }
diff --git a/moli/src/allocator.rs b/moli/src/allocator.rs
index 8bb79703b..2bbccd434 100644
--- a/moli/src/allocator.rs
+++ b/moli/src/allocator.rs
@@ -1,11 +1,11 @@
-//! Process-wide allocator configuration for the `moli` executable.
+//! Process-wide fallback allocator configuration for the `moli` executable.
//!
-//! Moli keeps one process alive while many page targets are opened and
-//! closed. The low-resource jemalloc profile below favors returning those
-//! short-lived page allocations to the operating system over maximizing
-//! allocator throughput. Keep this configuration beside the allocator
-//! declaration: changing either side requires another deterministic DOM and
-//! full Spider Bench A/B.
+//! Targets with an official pointer-compressed rusty_v8 archive use its
+//! PartitionAlloc shim instead. On other non-Windows targets, the low-resource
+//! jemalloc profile below favors returning short-lived page allocations to the
+//! operating system over maximizing allocator throughput. Keep this
+//! configuration beside the allocator declaration: changing either side
+//! requires another deterministic DOM and full Spider Bench A/B.
//!
//! `override_allocator_on_supported_platforms` makes jemalloc export the
//! unprefixed C allocation symbols on Linux. This distinction is important:
diff --git a/moli/src/main.rs b/moli/src/main.rs
index 8d6768bd3..70729443c 100644
--- a/moli/src/main.rs
+++ b/moli/src/main.rs
@@ -7,7 +7,17 @@
use anyhow::Result;
use std::process::ExitCode;
-#[cfg(all(feature = "jemalloc", not(target_os = "windows")))]
+#[cfg(all(
+ feature = "jemalloc",
+ not(target_os = "windows"),
+ not(any(
+ all(target_os = "linux", target_env = "gnu", target_arch = "x86_64"),
+ all(
+ target_os = "macos",
+ any(target_arch = "x86_64", target_arch = "aarch64")
+ )
+ ))
+))]
mod allocator;
fn run() -> Result<()> {
diff --git a/vendor/v8-146.9.0/build.rs b/vendor/v8-146.9.0/build.rs
index 8abcb39f1..03cb11570 100644
--- a/vendor/v8-146.9.0/build.rs
+++ b/vendor/v8-146.9.0/build.rs
@@ -508,6 +508,20 @@ fn build_moli_v8_ext(sources: &[PathBuf]) {
.include("v8/include")
.std("c++20")
.flag_if_supported("-w");
+ // These definitions change V8's public header ABI and must match the
+ // prebuilt archive (or the GN configuration used for a source build).
+ if env::var("CARGO_FEATURE_V8_ENABLE_POINTER_COMPRESSION").is_ok() {
+ build
+ .define("V8_COMPRESS_POINTERS", None)
+ .define("V8_COMPRESS_POINTERS_IN_SHARED_CAGE", None)
+ .define("V8_31BIT_SMIS_ON_64BIT_ARCH", None);
+ }
+ if env::var("CARGO_FEATURE_V8_ENABLE_SANDBOX").is_ok() {
+ build.define("V8_ENABLE_SANDBOX", None);
+ }
+ if env::var("CARGO_FEATURE_V8_ENABLE_V8_CHECKS").is_ok() {
+ build.define("V8_ENABLE_CHECKS", None);
+ }
let compiler = build.get_compiler();
if compiler.is_like_msvc() && !compiler.is_like_clang_cl() {
build.flag("/Zc:__cplusplus");