build releases with mimalloc

This commit is contained in:
Scott Lamb 2025-04-03 09:16:04 -07:00
parent 0ccc6d0769
commit 39b6f6c49c
10 changed files with 79 additions and 18 deletions

View File

@ -90,7 +90,7 @@ jobs:
working-directory: server working-directory: server
target: ${{ matrix.rust_target }} target: ${{ matrix.rust_target }}
command: build command: build
args: --release --features bundled args: --release --features bundled,mimalloc
- name: Upload Docker Artifact - name: Upload Docker Artifact
run: | run: |
tag="${DOCKER_TAG}-${{ matrix.arch }}" tag="${DOCKER_TAG}-${{ matrix.arch }}"

View File

@ -8,6 +8,11 @@ upgrades, e.g. `v0.6.x` -> `v0.7.x`. The config file format and
[API](ref/api.md) currently have no stability guarantees, so they may change [API](ref/api.md) currently have no stability guarantees, so they may change
even on minor releases, e.g. `v0.7.5` -> `v0.7.6`. even on minor releases, e.g. `v0.7.5` -> `v0.7.6`.
## unreleased
* Release with `mimalloc` allocator, which is significantly faster than the memory
allocator built into `musl`.
## v0.7.20 (2025-01-31) ## v0.7.20 (2025-01-31)
* H.265 fixes. * H.265 fixes.

18
server/Cargo.lock generated
View File

@ -284,6 +284,12 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "cty"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]] [[package]]
name = "cursive" name = "cursive"
version = "0.21.1" version = "0.21.1"
@ -1072,6 +1078,17 @@ version = "0.2.169"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
[[package]]
name = "libmimalloc-sys"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b20daca3a4ac14dbdc753c5e90fc7b490a48a9131daed3c9a9ced7b2defd37b"
dependencies = [
"cc",
"cty",
"libc",
]
[[package]] [[package]]
name = "libredox" name = "libredox"
version = "0.1.3" version = "0.1.3"
@ -1215,6 +1232,7 @@ dependencies = [
"futures", "futures",
"jiff", "jiff",
"libc", "libc",
"libmimalloc-sys",
"nix", "nix",
"nom", "nom",
"rusqlite", "rusqlite",

View File

@ -18,6 +18,7 @@ nightly = ["db/nightly"]
bundled = ["rusqlite/bundled", "bundled-ui"] bundled = ["rusqlite/bundled", "bundled-ui"]
bundled-ui = [] bundled-ui = []
mimalloc = ["base/mimalloc"]
[workspace] [workspace]
members = ["base", "db"] members = ["base", "db"]
@ -42,10 +43,16 @@ uuid = { version = "1.1.2", features = ["serde", "std", "v7", "fast-rng"] }
base = { package = "moonfire-base", path = "base" } base = { package = "moonfire-base", path = "base" }
base64 = { workspace = true } base64 = { workspace = true }
blake3 = "1.0.0" blake3 = "1.0.0"
bpaf = { version = "0.9.15", features = ["autocomplete", "bright-color", "derive"]} bpaf = { version = "0.9.15", features = [
"autocomplete",
"bright-color",
"derive",
] }
bytes = "1" bytes = "1"
byteorder = "1.0" byteorder = "1.0"
cursive = { version = "0.21.1", default-features = false, features = ["termion-backend"] } cursive = { version = "0.21.1", default-features = false, features = [
"termion-backend",
] }
data-encoding = "2.7.0" data-encoding = "2.7.0"
db = { package = "moonfire-db", path = "db" } db = { package = "moonfire-db", path = "db" }
futures = "0.3" futures = "0.3"
@ -70,7 +77,13 @@ rusqlite = { workspace = true }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
smallvec = { version = "1.7", features = ["union"] } smallvec = { version = "1.7", features = ["union"] }
tokio = { version = "1.24", features = ["macros", "rt-multi-thread", "signal", "sync", "time"] } tokio = { version = "1.24", features = [
"macros",
"rt-multi-thread",
"signal",
"sync",
"time",
] }
tokio-tungstenite = "0.26.1" tokio-tungstenite = "0.26.1"
toml = "0.8" toml = "0.8"
tracing = { workspace = true, features = ["log"] } tracing = { workspace = true, features = ["log"] }
@ -96,7 +109,9 @@ walkdir = "2.3.3"
[dev-dependencies] [dev-dependencies]
mp4 = { git = "https://github.com/scottlamb/mp4-rust", branch = "moonfire" } mp4 = { git = "https://github.com/scottlamb/mp4-rust", branch = "moonfire" }
num-rational = { version = "0.4.0", default-features = false, features = ["std"] } num-rational = { version = "0.4.0", default-features = false, features = [
"std",
] }
reqwest = { version = "0.12.0", default-features = false, features = ["json"] } reqwest = { version = "0.12.0", default-features = false, features = ["json"] }
tempfile = "3.2.0" tempfile = "3.2.0"
tracing-test = "0.2.4" tracing-test = "0.2.4"

View File

@ -9,6 +9,7 @@ publish = false
rust-version = "1.82" rust-version = "1.82"
[features] [features]
mimalloc = ["dep:libmimalloc-sys"]
nightly = [] nightly = []
[lib] [lib]
@ -20,6 +21,10 @@ coded = { git = "https://github.com/scottlamb/coded", rev = "2c97994974a73243d5d
futures = "0.3" futures = "0.3"
jiff = { workspace = true } jiff = { workspace = true }
libc = "0.2" libc = "0.2"
libmimalloc-sys = { version = "0.1.41", features = [
"override",
"extended",
], optional = true }
nix = { workspace = true, features = ["time"] } nix = { workspace = true, features = ["time"] }
nom = "7.0.0" nom = "7.0.0"
rusqlite = { workspace = true } rusqlite = { workspace = true }

View File

@ -75,3 +75,16 @@ impl std::ops::Deref for Condvar {
&self.0 &self.0
} }
} }
pub fn ensure_malloc_used() {
#[cfg(feature = "mimalloc")]
{
// This is a load-bearing debug line.
// Building `libmimalloc-sys` with the `override` feature will override `malloc` and
// `free` as used through the Rust global allocator, SQLite, and `libc`. But...`cargo`
// doesn't seem to build `libmimalloc-sys` at all if it's not referenced from Rust code.
tracing::debug!("mimalloc version {}", unsafe {
libmimalloc_sys::mi_version()
})
}
}

View File

@ -27,7 +27,9 @@ itertools = { workspace = true }
jiff = { workspace = true } jiff = { workspace = true }
libc = "0.2" libc = "0.2"
nix = { workspace = true, features = ["dir", "feature", "fs", "mman"] } nix = { workspace = true, features = ["dir", "feature", "fs", "mman"] }
num-rational = { version = "0.4.0", default-features = false, features = ["std"] } num-rational = { version = "0.4.0", default-features = false, features = [
"std",
] }
pretty-hex = { workspace = true } pretty-hex = { workspace = true }
protobuf = "3.0" protobuf = "3.0"
ring = { workspace = true } ring = { workspace = true }

View File

@ -656,6 +656,7 @@ mod bench {
/// Benchmarks the decoder, which is performance-critical for .mp4 serving. /// Benchmarks the decoder, which is performance-critical for .mp4 serving.
#[bench] #[bench]
fn bench_decoder(b: &mut test::Bencher) { fn bench_decoder(b: &mut test::Bencher) {
crate::testutil::init();
let data = include_bytes!("testdata/video_sample_index.bin"); let data = include_bytes!("testdata/video_sample_index.bin");
b.bytes = data.len() as u64; b.bytes = data.len() as u64;
b.iter(|| { b.iter(|| {

View File

@ -37,6 +37,7 @@ pub const TEST_VIDEO_SAMPLE_ENTRY_DATA: &[u8] =
/// * use a fast but insecure password hashing format. /// * use a fast but insecure password hashing format.
pub fn init() { pub fn init() {
INIT.call_once(|| { INIT.call_once(|| {
base::ensure_malloc_used();
base::tracing_setup::install_for_tests(); base::tracing_setup::install_for_tests();
base::time::testutil::init_zone(); base::time::testutil::init_zone();
crate::auth::set_test_config(); crate::auth::set_test_config();

View File

@ -77,6 +77,7 @@ fn main() {
} }
base::tracing_setup::install(); base::tracing_setup::install();
base::time::init_zone(jiff::tz::TimeZone::system); base::time::init_zone(jiff::tz::TimeZone::system);
base::ensure_malloc_used();
// Get the program name from the OS (e.g. if invoked as `target/debug/nvr`: `nvr`), // Get the program name from the OS (e.g. if invoked as `target/debug/nvr`: `nvr`),
// falling back to the crate name if conversion to a path/UTF-8 string fails. // falling back to the crate name if conversion to a path/UTF-8 string fails.