mirror of
https://github.com/servo/servo.git
synced 2025-06-06 00:25:37 +00:00
Allow usage of the mimalloc allocator
Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
8d086b9fe5
commit
48faed54f7
4 changed files with 58 additions and 2 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -1488,6 +1488,12 @@ dependencies = [
|
|||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cty"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
|
||||
|
||||
[[package]]
|
||||
name = "cursor-icon"
|
||||
version = "1.2.0"
|
||||
|
@ -4311,6 +4317,17 @@ version = "0.2.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
|
||||
|
||||
[[package]]
|
||||
name = "libmimalloc-sys"
|
||||
version = "0.1.42"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec9d6fac27761dabcd4ee73571cdb06b7022dc99089acbe5435691edffaac0f4"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cty",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.3"
|
||||
|
@ -4622,6 +4639,15 @@ dependencies = [
|
|||
"servo_url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mimalloc"
|
||||
version = "0.1.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "995942f432bbb4822a7e9c3faa87a695185b0d09273ba85f097b54f4e458f2af"
|
||||
dependencies = [
|
||||
"libmimalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
|
@ -6894,6 +6920,8 @@ name = "servo_allocator"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"libmimalloc-sys",
|
||||
"mimalloc",
|
||||
"tikv-jemalloc-sys",
|
||||
"tikv-jemallocator",
|
||||
"windows-sys 0.59.0",
|
||||
|
|
|
@ -12,6 +12,7 @@ path = "lib.rs"
|
|||
|
||||
[features]
|
||||
use-system-allocator = ["libc"]
|
||||
use-mimalloc = ["mimalloc", "libmimalloc-sys"]
|
||||
|
||||
[target.'cfg(not(any(windows, target_env = "ohos")))'.dependencies]
|
||||
libc = { workspace = true, optional = true }
|
||||
|
@ -23,3 +24,7 @@ windows-sys = { workspace = true, features = ["Win32_System_Memory"] }
|
|||
|
||||
[target.'cfg(target_env = "ohos")'.dependencies]
|
||||
libc = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
mimalloc = { version = "0.1", features = ["extended"], optional = true }
|
||||
libmimalloc-sys = { version = "0.1", optional = true }
|
||||
|
|
|
@ -9,7 +9,7 @@ static ALLOC: Allocator = Allocator;
|
|||
|
||||
pub use crate::platform::*;
|
||||
|
||||
#[cfg(not(any(windows, feature = "use-system-allocator", target_env = "ohos")))]
|
||||
#[cfg(not(any(windows, feature = "use-system-allocator", feature = "use-mimalloc", target_env = "ohos")))]
|
||||
mod platform {
|
||||
use std::os::raw::c_void;
|
||||
|
||||
|
@ -32,6 +32,7 @@ mod platform {
|
|||
|
||||
#[cfg(all(
|
||||
not(windows),
|
||||
not(feature = "use-mimalloc"),
|
||||
any(feature = "use-system-allocator", target_env = "ohos")
|
||||
))]
|
||||
mod platform {
|
||||
|
@ -60,7 +61,7 @@ mod platform {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[cfg(all(windows, not(feature = "use-mimalloc")))]
|
||||
mod platform {
|
||||
pub use std::alloc::System as Allocator;
|
||||
use std::os::raw::c_void;
|
||||
|
@ -85,3 +86,24 @@ mod platform {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "use-mimalloc")]
|
||||
mod platform {
|
||||
use std::os::raw::c_void;
|
||||
|
||||
pub use mimalloc::MiMalloc as Allocator;
|
||||
|
||||
/// Get the size of a heap block.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Passing a non-heap allocated pointer to this function results in undefined behavior.
|
||||
pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize {
|
||||
unsafe { Allocator.usable_size(ptr as _) }
|
||||
}
|
||||
|
||||
/// Memory allocation APIs compatible with libc
|
||||
pub mod libc_compat {
|
||||
pub use libmimalloc_sys::{ mi_free as free, mi_malloc as malloc, mi_realloc as realloc };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ webdriver = ["libservo/webdriver"]
|
|||
webgl_backtrace = ["libservo/webgl_backtrace"]
|
||||
webgpu = ["libservo/webgpu"]
|
||||
webxr = ["libservo/webxr"]
|
||||
use-mimalloc = ["servo_allocator/use-mimalloc"]
|
||||
|
||||
[dependencies]
|
||||
cfg-if = { workspace = true }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue