feat(tvix): Switch to jemalloc

Switch tvix to using jemalloc as the default global allocator on
supported (eg, non-msvc) platforms. This gives a pretty reasonable
performance boost basically for free:

int                     time:   [24.361 µs 24.386 µs 24.418 µs]
                        change: [-19.355% -18.859% -18.527%] (p = 0.00 < 0.05)
                        Performance has improved.

merge small attrs       time:   [37.201 µs 37.328 µs 37.442 µs]
                        change: [-24.609% -24.266% -23.982%] (p = 0.00 < 0.05)
                        Performance has improved.

merge large attrs with small attrs
                        time:   [20.030 ms 20.135 ms 20.251 ms]
                        change: [-4.2811% -3.2549% -2.3807%] (p = 0.00 < 0.05)
                        Performance has improved.

hello outpath           time:   [967.91 ms 974.07 ms 983.33 ms]
                        change: [-5.5008% -4.4552% -3.4099%] (p = 0.00 < 0.05)
                        Performance has improved.

Change-Id: I6c6e6e3295ec2fca01ea28dc37bcb201cd811767
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10851
Tested-by: BuildkiteCI
Reviewed-by: sterni <sternenseemann@systemli.org>
Autosubmit: aspen <root@gws.fyi>
Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
Aspen Smith 2024-02-13 13:23:39 -05:00 committed by clbot
parent 08e520b7cc
commit d0ab3c8d15
8 changed files with 132 additions and 0 deletions

23
tvix/Cargo.lock generated
View file

@ -3660,6 +3660,26 @@ dependencies = [
"once_cell", "once_cell",
] ]
[[package]]
name = "tikv-jemalloc-sys"
version = "0.5.4+5.3.0-patched"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9402443cb8fd499b6f327e40565234ff34dbda27460c5b47db0db77443dd85d1"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "tikv-jemallocator"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "965fe0c26be5c56c94e38ba547249074803efd52adfb66de62107d95aab3eaca"
dependencies = [
"libc",
"tikv-jemalloc-sys",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.34" version = "0.3.34"
@ -4181,6 +4201,7 @@ dependencies = [
"rnix", "rnix",
"rustyline", "rustyline",
"thiserror", "thiserror",
"tikv-jemallocator",
"tokio", "tokio",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
@ -4225,6 +4246,7 @@ dependencies = [
"tabwriter", "tabwriter",
"tempfile", "tempfile",
"test-strategy", "test-strategy",
"tikv-jemallocator",
"toml", "toml",
"tvix-eval-builtin-macros", "tvix-eval-builtin-macros",
] ]
@ -4265,6 +4287,7 @@ dependencies = [
"sha2", "sha2",
"tempfile", "tempfile",
"thiserror", "thiserror",
"tikv-jemallocator",
"tokio", "tokio",
"tokio-tar", "tokio-tar",
"tokio-util", "tokio-util",

View file

@ -11190,6 +11190,72 @@ rec {
]; ];
features = { }; features = { };
}; };
"tikv-jemalloc-sys" = rec {
crateName = "tikv-jemalloc-sys";
version = "0.5.4+5.3.0-patched";
edition = "2018";
links = "jemalloc";
sha256 = "1lc5vm1p9dqdvd3mn3264zddnd7z6i95ch3y69prnjgxp0y480ll";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>"
"The TiKV Project Developers"
];
dependencies = [
{
name = "libc";
packageId = "libc";
usesDefaultFeatures = false;
}
];
buildDependencies = [
{
name = "cc";
packageId = "cc";
}
];
features = {
"background_threads" = [ "background_threads_runtime_support" ];
"default" = [ "background_threads_runtime_support" ];
};
resolvedDefaultFeatures = [ "background_threads_runtime_support" ];
};
"tikv-jemallocator" = rec {
crateName = "tikv-jemallocator";
version = "0.5.4";
edition = "2018";
sha256 = "1jpanfm9az8hcbg6dyxdabykx03lj0j4g9cbwfa6rig5dg1f0pwn";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
"Gonzalo Brito Gadeschi <gonzalobg88@gmail.com>"
"Simon Sapin <simon.sapin@exyr.org>"
"Steven Fackler <sfackler@gmail.com>"
"The TiKV Project Developers"
];
dependencies = [
{
name = "libc";
packageId = "libc";
usesDefaultFeatures = false;
}
{
name = "tikv-jemalloc-sys";
packageId = "tikv-jemalloc-sys";
usesDefaultFeatures = false;
}
];
features = {
"background_threads" = [ "tikv-jemalloc-sys/background_threads" ];
"background_threads_runtime_support" = [ "tikv-jemalloc-sys/background_threads_runtime_support" ];
"debug" = [ "tikv-jemalloc-sys/debug" ];
"default" = [ "background_threads_runtime_support" ];
"disable_initial_exec_tls" = [ "tikv-jemalloc-sys/disable_initial_exec_tls" ];
"profiling" = [ "tikv-jemalloc-sys/profiling" ];
"stats" = [ "tikv-jemalloc-sys/stats" ];
"unprefixed_malloc_on_supported_platforms" = [ "tikv-jemalloc-sys/unprefixed_malloc_on_supported_platforms" ];
};
resolvedDefaultFeatures = [ "background_threads_runtime_support" "default" ];
};
"time" = rec { "time" = rec {
crateName = "time"; crateName = "time";
version = "0.3.34"; version = "0.3.34";
@ -13220,6 +13286,11 @@ rec {
name = "thiserror"; name = "thiserror";
packageId = "thiserror"; packageId = "thiserror";
} }
{
name = "tikv-jemallocator";
packageId = "tikv-jemallocator";
target = { target, features }: (!("msvc" == target."env" or null));
}
{ {
name = "tokio"; name = "tokio";
packageId = "tokio"; packageId = "tokio";
@ -13414,6 +13485,11 @@ rec {
name = "tempfile"; name = "tempfile";
packageId = "tempfile"; packageId = "tempfile";
} }
{
name = "tikv-jemallocator";
packageId = "tikv-jemallocator";
target = { target, features }: (!("msvc" == target."env" or null));
}
]; ];
features = { features = {
"arbitrary" = [ "proptest" "test-strategy" "imbl/proptest" ]; "arbitrary" = [ "proptest" "test-strategy" "imbl/proptest" ];
@ -13534,6 +13610,11 @@ rec {
name = "thiserror"; name = "thiserror";
packageId = "thiserror"; packageId = "thiserror";
} }
{
name = "tikv-jemallocator";
packageId = "tikv-jemallocator";
target = { target, features }: (!("msvc" == target."env" or null));
}
{ {
name = "tokio"; name = "tokio";
packageId = "tokio"; packageId = "tokio";

View file

@ -26,3 +26,6 @@ tracing-subscriber = "0.3.16"
[dependencies.wu-manber] [dependencies.wu-manber]
git = "https://github.com/tvlfyi/wu-manber.git" git = "https://github.com/tvlfyi/wu-manber.git"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5"

View file

@ -18,6 +18,13 @@ use tvix_glue::tvix_io::TvixIO;
use tvix_glue::tvix_store_io::TvixStoreIO; use tvix_glue::tvix_store_io::TvixStoreIO;
use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path}; use tvix_glue::{builtins::add_derivation_builtins, configure_nix_path};
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
#[derive(Parser, Clone)] #[derive(Parser, Clone)]
struct Args { struct Args {
#[arg(long)] #[arg(long)]

View file

@ -42,6 +42,9 @@ pretty_assertions = "1.2.1"
rstest = "0.19.0" rstest = "0.19.0"
tempfile = "3.3.0" tempfile = "3.3.0"
[target.'cfg(not(target_env = "msvc"))'.dev-dependencies]
tikv-jemallocator = "0.5"
[features] [features]
default = ["impure", "arbitrary", "nix_tests"] default = ["impure", "arbitrary", "nix_tests"]

View file

@ -1,5 +1,11 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use itertools::Itertools; use itertools::Itertools;
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
fn interpret(code: &str) { fn interpret(code: &str) {
tvix_eval::Evaluation::new_pure().evaluate(code, None); tvix_eval::Evaluation::new_pure().evaluate(code, None);

View file

@ -33,6 +33,9 @@ walkdir = "2.4.0"
[dependencies.wu-manber] [dependencies.wu-manber]
git = "https://github.com/tvlfyi/wu-manber.git" git = "https://github.com/tvlfyi/wu-manber.git"
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.5"
[dev-dependencies] [dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] } criterion = { version = "0.5", features = ["html_reports"] }
hex-literal = "0.4.1" hex-literal = "0.4.1"

View file

@ -1,6 +1,8 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion}; use criterion::{black_box, criterion_group, criterion_main, Criterion};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::{env, rc::Rc, sync::Arc, time::Duration}; use std::{env, rc::Rc, sync::Arc, time::Duration};
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
use tvix_build::buildservice::DummyBuildService; use tvix_build::buildservice::DummyBuildService;
use tvix_eval::{builtins::impure_builtins, EvalIO}; use tvix_eval::{builtins::impure_builtins, EvalIO};
use tvix_glue::{ use tvix_glue::{
@ -11,6 +13,10 @@ use tvix_glue::{
}; };
use tvix_store::utils::construct_services; use tvix_store::utils::construct_services;
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
lazy_static! { lazy_static! {
static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap(); static ref TOKIO_RUNTIME: tokio::runtime::Runtime = tokio::runtime::Runtime::new().unwrap();
} }