mirror of
https://github.com/DefectingCat/candy
synced 2025-07-15 00:31:33 +00:00
perf: change memory allocator to mimalloc
This commit is contained in:
90
Cargo.lock
generated
90
Cargo.lock
generated
@ -93,15 +93,15 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.96"
|
||||
version = "1.0.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4"
|
||||
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||
|
||||
[[package]]
|
||||
name = "async-compression"
|
||||
version = "0.4.18"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df895a515f70646414f4b45c0b79082783b80552b373a68283012928df56f522"
|
||||
checksum = "59a194f9d963d8099596278594b3107448656ba73831c9d8c783e613ce86da64"
|
||||
dependencies = [
|
||||
"brotli",
|
||||
"flate2",
|
||||
@ -217,9 +217,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bytes"
|
||||
version = "1.10.0"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9"
|
||||
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
|
||||
|
||||
[[package]]
|
||||
name = "candy"
|
||||
@ -235,6 +235,7 @@ dependencies = [
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-util",
|
||||
"mimalloc",
|
||||
"rustls",
|
||||
"rustls-pemfile",
|
||||
"serde",
|
||||
@ -286,9 +287,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.31"
|
||||
version = "4.5.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767"
|
||||
checksum = "e2c80cae4c3350dd8f1272c73e83baff9a6ba550b8bfbe651b3c45b78cd1751e"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
@ -296,9 +297,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.31"
|
||||
version = "4.5.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863"
|
||||
checksum = "0123e386f691c90aa228219b5b1ee72d465e8e231c79e9c82324f016a62a741c"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
@ -308,9 +309,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.28"
|
||||
version = "4.5.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed"
|
||||
checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
@ -531,9 +532,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.2.0"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
|
||||
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
@ -552,12 +553,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "http-body-util"
|
||||
version = "0.1.2"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f"
|
||||
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
@ -702,6 +703,16 @@ dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07d0e07885d6a754b9c7993f2625187ad694ee985d60f23355ff0e7077261502"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.15"
|
||||
@ -739,6 +750,15 @@ version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99585191385958383e13f6b822e6b6d8d9cf928e7d286ceb092da92b43c87bc1"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
@ -981,9 +1001,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.23"
|
||||
version = "0.23.25"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395"
|
||||
checksum = "822ee9188ac4ec04a2f0531e55d035fb2de73f18b41a63c70c2712503b6fb13c"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"log",
|
||||
@ -1024,9 +1044,9 @@ checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.102.8"
|
||||
version = "0.103.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"
|
||||
checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03"
|
||||
dependencies = [
|
||||
"aws-lc-rs",
|
||||
"ring",
|
||||
@ -1074,18 +1094,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.218"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60"
|
||||
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.218"
|
||||
version = "1.0.219"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b"
|
||||
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1175,18 +1195,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.11"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
|
||||
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.11"
|
||||
version = "2.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
|
||||
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -1205,9 +1225,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.43.0"
|
||||
version = "1.44.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e"
|
||||
checksum = "f382da615b842244d4b8738c82ed1275e6c5dd90c459a30941cd07080b06c91a"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
@ -1234,9 +1254,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.1"
|
||||
version = "0.26.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f6d0975eaace0cf0fcadee4e4aaa5da15b5c079146f2cffb67c113be122bf37"
|
||||
checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b"
|
||||
dependencies = [
|
||||
"rustls",
|
||||
"tokio",
|
||||
@ -1244,9 +1264,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tokio-util"
|
||||
version = "0.7.13"
|
||||
version = "0.7.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078"
|
||||
checksum = "6b9590b93e6fcc1739458317cccd391ad3955e2bde8913edf6f95f9e65a8f034"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
|
25
Cargo.toml
25
Cargo.toml
@ -19,27 +19,28 @@ default = ["ring"]
|
||||
|
||||
[dependencies]
|
||||
# core
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
tokio-util = "0.7.13"
|
||||
tokio = { version = "1.44.1", features = ["full"] }
|
||||
tokio-util = "0.7.14"
|
||||
hyper = { version = "1.6.0", features = ["full"] }
|
||||
hyper-util = { version = "0.1.10", features = ["full"] }
|
||||
http = "1.2.0"
|
||||
http-body-util = "0.1.2"
|
||||
http = "1.3.1"
|
||||
http-body-util = "0.1.3"
|
||||
futures-util = "0.3.31"
|
||||
async-compression = { version = "0.4.18", features = [
|
||||
async-compression = { version = "0.4.22", features = [
|
||||
"tokio",
|
||||
"zstd",
|
||||
"gzip",
|
||||
"deflate",
|
||||
"brotli",
|
||||
] }
|
||||
mimalloc = "0.1.44"
|
||||
# ssl
|
||||
rustls = { version = "0.23.23", default-features = false, features = [
|
||||
rustls = { version = "0.23.25", default-features = false, features = [
|
||||
"logging",
|
||||
"std",
|
||||
"tls12",
|
||||
] }
|
||||
tokio-rustls = { version = "0.26.1", default-features = false, features = [
|
||||
tokio-rustls = { version = "0.26.2", default-features = false, features = [
|
||||
"logging",
|
||||
"tls12",
|
||||
] }
|
||||
@ -50,15 +51,15 @@ hyper-rustls = { version = "0.27.5", default-features = false, features = [
|
||||
"http1",
|
||||
] }
|
||||
# tools
|
||||
thiserror = "2.0.11"
|
||||
anyhow = "1.0.96"
|
||||
serde = { version = "1.0.218", features = ["derive"] }
|
||||
thiserror = "2.0.12"
|
||||
anyhow = "1.0.97"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
toml = "0.8.20"
|
||||
bytes = "1.10.0"
|
||||
bytes = "1.10.1"
|
||||
# logging
|
||||
tracing = "0.1.41"
|
||||
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
|
||||
clap = { version = "4.5.31", features = ["derive"] }
|
||||
clap = { version = "4.5.33", features = ["derive"] }
|
||||
rustls-pemfile = "2.2.0"
|
||||
|
||||
[profile.dev]
|
||||
|
32
build.rs
32
build.rs
@ -17,8 +17,10 @@ macro_rules! set_env {
|
||||
|
||||
fn main() {
|
||||
rustc_info();
|
||||
commit_info();
|
||||
}
|
||||
|
||||
/// Get rustc version info
|
||||
fn rustc_info() {
|
||||
let rustc_output = Command::new("rustc")
|
||||
.args(["-vV"])
|
||||
@ -30,6 +32,34 @@ fn rustc_info() {
|
||||
.split('\n')
|
||||
.filter(|info| !info.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
set_env!("RUA_COMPILER={}", info_arr[0]);
|
||||
}
|
||||
|
||||
/// Get commit info
|
||||
/// If failed, set RUA_COMMIT=unknown
|
||||
fn commit_info() {
|
||||
let output = Command::new("git").args(["rev-parse", "HEAD"]).output();
|
||||
// get commit info
|
||||
let Ok(output) = output else {
|
||||
warn!("get commit info failed");
|
||||
set_env!("RUA_COMMIT={}", "unknown");
|
||||
return;
|
||||
};
|
||||
// check is dirty
|
||||
let dirty = Command::new("git")
|
||||
.args(["diff", "--quiet"])
|
||||
.output()
|
||||
.is_ok();
|
||||
let commit = String::from_utf8_lossy(&output.stdout)
|
||||
.chars()
|
||||
.take(7)
|
||||
.collect::<String>();
|
||||
let commit = if commit.is_empty() {
|
||||
"unknown".to_string()
|
||||
} else if dirty {
|
||||
format!("{commit}-dirty")
|
||||
} else {
|
||||
commit
|
||||
};
|
||||
set_env!("RUA_COMMIT={}", commit);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const OS: &str = env::consts::OS;
|
||||
pub const ARCH: &str = env::consts::ARCH;
|
||||
pub const COMPILER: &str = env!("RUA_COMPILER");
|
||||
pub const COMMIT: &str = env!("RUA_COMMIT");
|
||||
|
||||
// config defaults
|
||||
pub const HOST_INDEX: [&str; 1] = ["index.html"];
|
||||
|
10
src/main.rs
10
src/main.rs
@ -2,7 +2,7 @@ use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use clap::Parser;
|
||||
use config::Settings;
|
||||
use consts::COMPILER;
|
||||
use consts::{COMMIT, COMPILER};
|
||||
use tokio::task::JoinSet;
|
||||
use tracing::{debug, info};
|
||||
|
||||
@ -11,6 +11,11 @@ use crate::{
|
||||
utils::init_logger,
|
||||
};
|
||||
|
||||
use mimalloc::MiMalloc;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: MiMalloc = MiMalloc;
|
||||
|
||||
mod cli;
|
||||
mod config;
|
||||
mod consts;
|
||||
@ -31,7 +36,8 @@ async fn main() -> Result<()> {
|
||||
// global config
|
||||
let settings = get_settings().with_context(|| "get global settings failed")?;
|
||||
debug!("settings {:?}", settings);
|
||||
info!("{}/{} {}", NAME, VERSION, COMPILER);
|
||||
info!("{}/{} {}", NAME, VERSION, COMMIT);
|
||||
info!("{}", COMPILER);
|
||||
info!("OS: {} {}", OS, ARCH);
|
||||
|
||||
let mut servers = settings
|
||||
|
Reference in New Issue
Block a user