Skip to content

Commit

Permalink
Tweak global allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Feb 22, 2024
1 parent 63d65d5 commit d491852
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
20 changes: 0 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ tempfile = "3.9"
tokio = { version = "1", features = ["full", "parking_lot"] }
tokio-stream = { version = "0.1", default-features = false, features = ["fs"] }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
[target.'cfg(not(any(target_env = "msvc", target_os = "macos")))'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["background_threads", "unprefixed_malloc_on_supported_platforms"] }

[target.'cfg(target_env = "msvc")'.dependencies]
mimalloc = { version = "0.1", default-features = false }
[target.'cfg(target_os = "macos")'.dependencies]
tikv-jemallocator = { version = "0.5", features = ["unprefixed_malloc_on_supported_platforms"] } # jemalloc not support background threads on macos

[target.'cfg(windows)'.dependencies]
tray-icon = { version = "0.11", default-features = false }
Expand Down
14 changes: 6 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ use inquire::{
CustomType, Text,
};
use log::{error, info, warn};
#[cfg(target_env = "msvc")]
use mimalloc::MiMalloc;
use once_cell::sync::Lazy;
use openssl::{
pkcs12::ParsedPkcs12_2,
Expand All @@ -36,8 +34,6 @@ use parking_lot::{Mutex, RwLock};
use regex::Regex;
use reqwest::Proxy;
use tempfile::TempPath;
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;
use tokio::{
fs::{self, try_exists, File},
io::{stderr, stdin, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader},
Expand Down Expand Up @@ -69,10 +65,12 @@ mod util;

#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
#[cfg(target_env = "msvc")]
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

// jemalloc config
#[cfg(not(target_env = "msvc"))]
#[no_mangle]
pub static mut malloc_conf: *const u8 = b"percpu_arena:phycpu,tcache:false,dirty_decay_ms:1000,muzzy_decay_ms:0\0".as_ptr();

static VERSION: Lazy<String> = Lazy::new(|| {
format!(
Expand Down

0 comments on commit d491852

Please sign in to comment.