Skip to content

Commit 4e128ca

Browse files
authored
perf: enable jemallocator for musl targets (#715)
* perf: enable jemallocator for musl targets * chore: add a feature for exposing internal api * build: fix conflicts between jemalloc & dhat
1 parent 232a959 commit 4e128ca

File tree

6 files changed

+49
-10
lines changed

6 files changed

+49
-10
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ jobs:
5454
- os: ubuntu-latest
5555
target: x86_64-unknown-linux-musl
5656
tool: cross
57+
extra-args: -F "shadowsocks, tuic, onion, jemallocator"
58+
- os: ubuntu-latest
59+
target: i686-unknown-linux-musl
60+
tool: cross
5761
extra-args: -F "shadowsocks, tuic, onion"
5862
# Linux x86 gnu static-crt
5963
- os: ubuntu-latest
@@ -85,7 +89,7 @@ jobs:
8589
- os: ubuntu-latest
8690
target: aarch64-unknown-linux-musl
8791
tool: cross
88-
extra-args: -F "shadowsocks, tuic, onion"
92+
extra-args: -F "shadowsocks, tuic, onion, jemallocator"
8993
- os: ubuntu-latest
9094
target: armv7-unknown-linux-musleabihf
9195
tool: cross
@@ -186,11 +190,11 @@ jobs:
186190
- os: ubuntu-latest
187191
target: x86_64-unknown-freebsd
188192
tool: cross
189-
extra-args: --verbose -F "shadowsocks, tuic"
193+
extra-args: -F "shadowsocks, tuic"
190194
- os: ubuntu-latest
191195
target: i686-unknown-freebsd
192196
tool: cross
193-
extra-args: --verbose -F "shadowsocks, tuic"
197+
extra-args: -F "shadowsocks, tuic"
194198
# Android
195199
- os: ubuntu-latest
196200
target: aarch64-linux-android

Cargo.lock

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

clash/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ edition = { workspace = true }
66

77
[features]
88
default = []
9+
910
shadowsocks = ["clash_lib/shadowsocks"]
1011
tuic = ["clash_lib/tuic"]
11-
bench = ["clash_lib/bench"]
1212
onion = ["clash_lib/onion"]
1313

14+
bench = ["clash_lib/bench"]
1415
dhat-heap = ["dep:dhat"]
15-
1616
tokio-console = ["clash_lib/tokio-console"]
17+
jemallocator = ["dep:tikv-jemallocator"]
1718

1819
[dependencies]
19-
clap = { version = "4.5.28", features = ["derive"] }
20+
clap = { version = "4", features = ["derive"] }
2021

2122
clash_lib = { path = "../clash_lib", default-features = false }
2223

23-
dhat = { version = "0.3.3", optional = true }
24+
dhat = { version = "0.3", optional = true }
25+
tikv-jemallocator = { version = "0.6", optional = true }

clash/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
#[global_allocator]
33
static ALLOC: dhat::Alloc = dhat::Alloc;
44

5+
#[cfg(all(feature = "jemallocator", not(feature = "dhat-heap")))]
6+
use tikv_jemallocator::Jemalloc;
7+
8+
#[cfg(all(feature = "jemallocator", not(feature = "dhat-heap")))]
9+
#[global_allocator]
10+
static GLOBAL: Jemalloc = Jemalloc;
11+
512
extern crate clash_lib as clash;
613

714
use clap::Parser;

clash_lib/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ version = { workspace = true }
55
edition = { workspace = true }
66

77
[features]
8-
default = ["tokio-console", "zero_copy"]
8+
default = ["zero_copy"]
9+
10+
internal = []
911
# Protos
1012
shadowsocks = ["dep:shadowsocks"]
1113
tuic = ["dep:tuic", "dep:tuic-quinn", "dep:register-count"]
1214
ssh = ["dep:russh", "dep:dirs", "dep:totp-rs"]
13-
bench = ["dep:criterion"]
1415
onion = ["dep:arti-client", "dep:tor-rtcompat", "arti-client/onion-service-client"]
15-
zero_copy = []
1616

17+
zero_copy = []
18+
bench = ["dep:criterion"]
1719
tokio-console = ["tokio/tracing"]
1820

1921
[dependencies]

clash_lib/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ use tracing::{debug, error, info};
3636

3737
mod app;
3838
mod common;
39+
#[cfg(feature = "internal")]
40+
pub mod config;
41+
#[cfg(not(feature = "internal"))]
3942
mod config;
4043
mod proxy;
4144
mod session;

0 commit comments

Comments
 (0)