From bd870a9d6c8382e83672cb9b8a294a819757cfb8 Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Fri, 23 Sep 2022 16:32:13 -0700 Subject: [PATCH] Shrink all SmallVecs by 8 bytes (#4951) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We weren't using the "union" cargo feature for the smallvec crate, which reduces the size of a SmallVec by one machine word. This feature requires Rust 1.49 but we already require much newer versions. When using Wasmtime to compile pulldown-cmark from Sightglass, this saves a decent amount of memory allocations and writes. According to `valgrind --tool=dhat`: - 6.2MiB (3.69%) less memory allocated over the program's lifetime - 0.5MiB (4.13%) less memory allocated at maximum heap size - 5.5MiB (1.88%) fewer bytes written to - 0.44% fewer instructions executed Sightglass reports a statistically significant runtime improvement too: compilation :: cycles :: benchmarks/pulldown-cmark/benchmark.wasm Δ = 24379323.60 ± 20051394.04 (confidence = 99%) shrink-abiarg-0406da67c.so is 1.01x to 1.13x faster than main-be690a468.so! [227506364 355007998.78 423280514] main-be690a468.so [227686018 330628675.18 406025344] shrink-abiarg-0406da67c.so compilation :: cycles :: benchmarks/spidermonkey/benchmark.wasm Δ = 360151622.56 ± 278294316.90 (confidence = 99%) shrink-abiarg-0406da67c.so is 1.01x to 1.07x faster than main-be690a468.so! [8709162212 8911001926.44 9535111576] main-be690a468.so [5058015392 8550850303.88 9282148438] shrink-abiarg-0406da67c.so compilation :: cycles :: benchmarks/bz2/benchmark.wasm Δ = 6936570.28 ± 6897696.38 (confidence = 99%) shrink-abiarg-0406da67c.so is 1.00x to 1.08x faster than main-be690a468.so! [155810934 175260571.20 234737344] main-be690a468.so [119128240 168324000.92 257451074] shrink-abiarg-0406da67c.so --- cranelift/codegen/Cargo.toml | 2 +- cranelift/egraph/Cargo.toml | 2 +- cranelift/frontend/Cargo.toml | 2 +- cranelift/interpreter/Cargo.toml | 2 +- cranelift/reader/Cargo.toml | 2 +- cranelift/wasm/Cargo.toml | 2 +- fuzz/Cargo.toml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index c5f58f9086..dfb1277670 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -24,7 +24,7 @@ log = { version = "0.4.6", default-features = false } serde = { version = "1.0.94", features = ["derive"], optional = true } bincode = { version = "1.2.1", optional = true } gimli = { version = "0.26.0", default-features = false, features = ["write"], optional = true } -smallvec = { version = "1.6.1" } +smallvec = { version = "1.6.1", features = ["union"] } regalloc2 = { version = "0.4.1", features = ["checker"] } souper-ir = { version = "2.1.0", optional = true } sha2 = { version = "0.9.0", optional = true } diff --git a/cranelift/egraph/Cargo.toml b/cranelift/egraph/Cargo.toml index 819ad25159..51683c4ae8 100644 --- a/cranelift/egraph/Cargo.toml +++ b/cranelift/egraph/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" [dependencies] cranelift-entity = { path = "../entity", version = "0.89.0" } log = { version = "0.4.6", default-features = false } -smallvec = { version = "1.6.1" } +smallvec = { version = "1.6.1", features = ["union"] } indexmap = { version = "1.9.1" } hashbrown = { version = "0.12.2", features = ["raw"] } fxhash = "0.2.1" diff --git a/cranelift/frontend/Cargo.toml b/cranelift/frontend/Cargo.toml index 80460f9590..fe0624a6a5 100644 --- a/cranelift/frontend/Cargo.toml +++ b/cranelift/frontend/Cargo.toml @@ -15,7 +15,7 @@ cranelift-codegen = { path = "../codegen", version = "0.89.0", default-features target-lexicon = "0.12" log = { version = "0.4.6", default-features = false } hashbrown = { version = "0.12", optional = true } -smallvec = { version = "1.6.1" } +smallvec = { version = "1.6.1", features = ["union"] } [features] default = ["std"] diff --git a/cranelift/interpreter/Cargo.toml b/cranelift/interpreter/Cargo.toml index cbabad0ef5..7410e35a3a 100644 --- a/cranelift/interpreter/Cargo.toml +++ b/cranelift/interpreter/Cargo.toml @@ -14,7 +14,7 @@ edition = "2021" cranelift-codegen = { path = "../codegen", version = "0.89.0" } cranelift-entity = { path = "../entity", version = "0.89.0" } log = { version = "0.4.8", default-features = false } -smallvec = "1.6.1" +smallvec = { version = "1.6.1", features = ["union"] } thiserror = "1.0.15" [target.x86_64-pc-windows-gnu.dependencies] diff --git a/cranelift/reader/Cargo.toml b/cranelift/reader/Cargo.toml index 6743033141..1125692ce9 100644 --- a/cranelift/reader/Cargo.toml +++ b/cranelift/reader/Cargo.toml @@ -11,7 +11,7 @@ edition = "2021" [dependencies] cranelift-codegen = { path = "../codegen", version = "0.89.0" } -smallvec = "1.6.1" +smallvec = { version = "1.6.1", features = ["union"] } target-lexicon = "0.12" [badges] diff --git a/cranelift/wasm/Cargo.toml b/cranelift/wasm/Cargo.toml index 5e4c0c2b02..0460f2f4a1 100644 --- a/cranelift/wasm/Cargo.toml +++ b/cranelift/wasm/Cargo.toml @@ -21,7 +21,7 @@ hashbrown = { version = "0.12", optional = true } itertools = "0.10.0" log = { version = "0.4.6", default-features = false } serde = { version = "1.0.94", features = ["derive"], optional = true } -smallvec = "1.6.1" +smallvec = { version = "1.6.1", features = ["union"] } [dev-dependencies] wat = "1.0.47" diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 1111473d47..9dc45c9da4 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -18,7 +18,7 @@ cranelift-interpreter = { path = "../cranelift/interpreter" } cranelift-fuzzgen = { path = "../cranelift/fuzzgen" } libfuzzer-sys = { version = "0.4.0", features = ["arbitrary-derive"] } target-lexicon = "0.12" -smallvec = "1.6.1" +smallvec = { version = "1.6.1", features = ["union"] } wasmtime = { path = "../crates/wasmtime" } wasmtime-fuzzing = { path = "../crates/fuzzing" } component-test-util = { path = "../crates/misc/component-test-util" }