Skip to content

Commit 3694b3e

Browse files
Using MiMallocator for better performance (#8534)
1 parent a24b120 commit 3694b3e

File tree

24 files changed

+127
-0
lines changed

24 files changed

+127
-0
lines changed

Cargo.lock

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ opt-level = 3
3131
opt-level = 3
3232
[profile.ci-dev.package."vector-map"]
3333
opt-level = 3
34+
[profile.ci-dev.package."mimalloc"]
35+
opt-level = 3
36+
[profile.ci-dev.package."libmimalloc-sys"]
37+
opt-level = 3
3438

3539
[workspace]
3640
resolver = "2"
@@ -123,6 +127,7 @@ itertools = { version = "0.14.0", default-features = false }
123127
keccak = "0.1.5"
124128
lalrpop-util = { version = "0.22.2", features = ["lexer"] }
125129
log = "0.4.27"
130+
mimalloc = { version = "0.1.48" }
126131
num-bigint = { version = "0.4.6", default-features = false }
127132
num-integer = "0.1.46"
128133
num-traits = { version = "0.2.19", default-features = false }

crates/bin/cairo-compile/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ description = "Cairo compiler executable for the Cairo programming language"
1010
anyhow.workspace = true
1111
clap.workspace = true
1212
log.workspace = true
13+
mimalloc = { workspace = true, optional = true }
1314
tracing.workspace = true
1415

1516
cairo-lang-compiler = { path = "../../cairo-lang-compiler", version = "~2.13.0" }
1617
cairo-lang-lowering = { path = "../../cairo-lang-lowering", version = "~2.13.0" }
1718
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "~2.13.0", features = ["tracing"] }
19+
20+
[features]
21+
mimalloc = ["dep:mimalloc"]

crates/bin/cairo-compile/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ use cairo_lang_compiler::{CompilerConfig, compile_cairo_project_at_path};
77
use cairo_lang_utils::logging::init_logging;
88
use clap::Parser;
99

10+
#[cfg(feature = "mimalloc")]
11+
#[global_allocator]
12+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
13+
1014
/// Options for the `inlining-strategy` arguments.
1115
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, clap::ValueEnum)]
1216
pub enum InliningStrategy {

crates/bin/cairo-execute/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ cairo-lang-runner = { path = "../../cairo-lang-runner", version = "~2.13.0" }
1919
cairo-lang-sierra-generator = { path = "../../cairo-lang-sierra-generator", version = "~2.13.0" }
2020
cairo-vm = { workspace = true, features = ["clap"] }
2121
clap.workspace = true
22+
mimalloc = { workspace = true, features = ["secure"], optional = true }
2223
num-bigint.workspace = true
2324
salsa.workspace = true
2425
serde_json.workspace = true
26+
27+
[features]
28+
29+
mimalloc = ["dep:mimalloc"]

crates/bin/cairo-execute/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ use clap::Parser;
3030
use num_bigint::BigInt;
3131
use salsa::Database;
3232

33+
#[cfg(feature = "mimalloc")]
34+
#[global_allocator]
35+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
36+
3337
/// Compiles a Cairo project and runs a function marked `#[executable]`.
3438
/// Exits with 1 if the compilation or run fails, otherwise 0.
3539
#[derive(Parser, Debug)]

crates/bin/cairo-format/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ clap.workspace = true
1111
colored.workspace = true
1212
ignore.workspace = true
1313
log.workspace = true
14+
mimalloc = { workspace = true, optional = true }
1415
tracing.workspace = true
1516

1617
cairo-lang-formatter = { path = "../../cairo-lang-formatter", version = "~2.13.0" }
1718
cairo-lang-utils = { path = "../../cairo-lang-utils", version = "~2.13.0", features = ["tracing"] }
19+
20+
[features]
21+
mimalloc = ["dep:mimalloc"]

crates/bin/cairo-format/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use ignore::WalkState::Continue;
1111
use ignore::{DirEntry, Error, ParallelVisitor, ParallelVisitorBuilder, WalkState};
1212
use log::warn;
1313

14+
#[cfg(feature = "mimalloc")]
15+
#[global_allocator]
16+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
17+
1418
/// Outputs a string to stderr if the verbose flag is true.
1519
fn eprintln_if_verbose(s: &str, verbose: bool) {
1620
if verbose {

crates/bin/cairo-run/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ description = "Runner executable for the Cairo programming language"
99
[dependencies]
1010
anyhow.workspace = true
1111
clap.workspace = true
12+
mimalloc = { workspace = true, optional = true }
1213

1314
cairo-lang-compiler = { path = "../../cairo-lang-compiler", version = "~2.13.0" }
1415
cairo-lang-diagnostics = { path = "../../cairo-lang-diagnostics", version = "~2.13.0" }
1516
cairo-lang-filesystem = { path = "../../cairo-lang-filesystem", version = "~2.13.0" }
1617
cairo-lang-runner = { path = "../../cairo-lang-runner", version = "~2.13.0" }
1718
cairo-lang-sierra-generator = { path = "../../cairo-lang-sierra-generator", version = "~2.13.0" }
1819
cairo-lang-starknet = { path = "../../cairo-lang-starknet", version = "~2.13.0" }
20+
21+
[features]
22+
mimalloc = ["dep:mimalloc"]

crates/bin/cairo-run/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ use cairo_lang_sierra_generator::replace_ids::{DebugReplacer, SierraIdReplacer};
1818
use cairo_lang_starknet::contract::{find_contracts, get_contracts_info};
1919
use clap::Parser;
2020

21+
#[cfg(feature = "mimalloc")]
22+
#[global_allocator]
23+
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
24+
2125
/// Compiles a Cairo project and runs the function `main`.
2226
/// Exits with 1 if the compilation or run fails, otherwise 0.
2327
#[derive(Parser, Debug)]

0 commit comments

Comments
 (0)