Skip to content

Commit 7ea2aed

Browse files
committed
perf: use mimalloc in CLI; document allocator recommendation in vastlint-core
- Add mimalloc as global allocator in vastlint-cli for better throughput when validating many large documents concurrently - Add performance/allocator section to vastlint-core crate docs with benchmark data (+628% throughput, p99 26x lower on 339KB files) and guidance for downstream Rust binary authors - Bump all crates and npm to 0.2.3
1 parent 8b466e6 commit 7ea2aed

7 files changed

Lines changed: 51 additions & 7 deletions

File tree

crates/vastlint-cli/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vastlint-cli"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
rust-version = "1.75"
66
authors = ["Aleks <aleks@vastlint.org>"]
@@ -17,7 +17,10 @@ name = "vastlint"
1717
path = "src/main.rs"
1818

1919
[dependencies]
20-
vastlint-core = { path = "../vastlint-core", version = "0.2.2" }
20+
vastlint-core = { path = "../vastlint-core", version = "0.2.3" }
21+
# High-throughput allocator — eliminates system-allocator contention when
22+
# validating many large VAST documents concurrently (see vastlint-core docs).
23+
mimalloc = { version = "0.1", default-features = false }
2124
# Argument parsing
2225
clap = { version = "4", features = ["derive"] }
2326
# Coloured terminal output

crates/vastlint-cli/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ use std::collections::HashMap;
22
use std::io::Read;
33
use std::process::ExitCode;
44

5+
use mimalloc::MiMalloc;
6+
#[global_allocator]
7+
static GLOBAL: MiMalloc = MiMalloc;
8+
59
use anstream::eprintln;
610
use anstyle::{AnsiColor, Color, Style};
711
use clap::{Parser, Subcommand, ValueEnum};

crates/vastlint-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vastlint-core"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
rust-version = "1.75"
66
authors = ["Aleks <aleks@vastlint.org>"]

crates/vastlint-core/src/lib.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,43 @@
1010
//! - [`validate_with_context`] -- validate with rule overrides or wrapper depth
1111
//! - [`all_rules`] -- list the full 108-rule catalog
1212
//!
13+
//! # Performance — allocator recommendation
14+
//!
15+
//! `vastlint-core` builds an owned document tree on every call (one heap
16+
//! allocation per XML element, attribute, and text node). Under concurrent
17+
//! load the system allocator becomes a bottleneck because all threads compete
18+
//! for a shared free-list lock.
19+
//!
20+
//! Switching to [`mimalloc`](https://docs.rs/mimalloc) in your **binary**
21+
//! crate eliminates this contention and gives dramatically better throughput
22+
//! at high concurrency, especially for larger documents:
23+
//!
24+
//! ```toml
25+
//! # Cargo.toml (your binary, not a library crate)
26+
//! [dependencies]
27+
//! mimalloc = { version = "0.1", default-features = false }
28+
//! ```
29+
//!
30+
//! ```rust,ignore
31+
//! // src/main.rs
32+
//! use mimalloc::MiMalloc;
33+
//! #[global_allocator]
34+
//! static GLOBAL: MiMalloc = MiMalloc;
35+
//! ```
36+
//!
37+
//! Measured on Apple M-series (10 threads, 339 KB VAST documents, 100k calls):
38+
//!
39+
//! | Allocator | Throughput | avg latency | p99 latency |
40+
//! |---|---|---|---|
41+
//! | system (default) | 7,966 tags/s | 1,246 µs | 24,260 µs |
42+
//! | mimalloc | 57,936 tags/s | 171 µs | 912 µs |
43+
//!
44+
//! **+628% throughput, p99 drops 26×.**
45+
//!
46+
//! > ⚠️ Do **not** set a global allocator in a library crate — it would
47+
//! > override the allocator for any host process that links you (Go, Python,
48+
//! > Ruby runtimes, etc.), which can cause heap corruption.
49+
//!
1350
//! # Quick start
1451
//!
1552
//! ```rust

crates/vastlint-ffi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vastlint-ffi"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
rust-version = "1.75"
66
authors = ["Aleks <aleks@vastlint.org>"]

crates/vastlint-wasm/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vastlint-wasm"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
rust-version = "1.75"
66
authors = ["Aleks <aleks@vastlint.org>"]
@@ -15,7 +15,7 @@ categories = ["parser-implementations", "wasm"]
1515
crate-type = ["cdylib"]
1616

1717
[dependencies]
18-
vastlint-core = { path = "../vastlint-core", version = "0.2.2" }
18+
vastlint-core = { path = "../vastlint-core", version = "0.2.3" }
1919
wasm-bindgen = "0.2"
2020
serde = { version = "1", features = ["derive"] }
2121
serde-wasm-bindgen = "0.6"

npm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vastlint",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "VAST XML validator — checks ad tags against IAB VAST 2.0 through 4.3",
55
"license": "Apache-2.0",
66
"author": "Alex Sekowski <alex@vastlint.org>",

0 commit comments

Comments
 (0)