Skip to content

Commit b036650

Browse files
quininerhardfist
authored andcommitted
feat: introduce allocative
1 parent 126822e commit b036650

File tree

46 files changed

+272
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+272
-6
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ wasmparser = { version = "0.222.0", default-features = false }
113113
winnow = { version = "0.7.12", default-features = false, features = ["std", "simd"] }
114114
xxhash-rust = { version = "0.8.14", default-features = false }
115115

116+
allocative = { package = "rspack-allocative", version = "0.3.5", default-features = false, features = [
117+
"camino",
118+
"dashmap",
119+
"hashbrown",
120+
"indexmap",
121+
"tokio",
122+
"once_cell",
123+
"ustr",
124+
"atomic_refcell",
125+
] }
126+
116127
# Pinned
117128
napi = { version = "3.1.6", default-features = false }
118129
napi-build = { version = "2.2.3", default-features = false }
@@ -418,6 +429,10 @@ unused_import_braces = "warn"
418429
unused_lifetimes = "warn"
419430
unused_macro_rules = "warn"
420431

432+
[workspace.lints.rust.unexpected_cfgs]
433+
level = "warn"
434+
check-cfg = ['cfg(allocative)']
435+
421436
[workspace.lints.clippy]
422437
cargo_common_metadata = "allow"
423438
empty_docs = "allow" # there are some false positives inside biome_wasm

crates/node_binding/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ debug_tool = ["rspack_binding_api/debug_tool"]
1717
info-level = ["tracing/release_max_level_info"]
1818
plugin = ["rspack_binding_api/plugin"]
1919
sftrace-setup = ["rspack_binding_api/sftrace-setup"]
20+
allocative = ["rspack_binding_api/allocative"]
2021

2122
[package.metadata.cargo-shear]
2223
# Adding napi-derive as a dependency to workaround an issue where `dts` will no longer work without it.

crates/node_binding/scripts/build.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ async function build() {
7878
features.push("sftrace-setup");
7979
rustflags.push("-Zinstrument-xray=always");
8080
}
81+
if (process.env.ALLOCATIVE) {
82+
features.push("allocative");
83+
rustflags.push("--cfg=allocative");
84+
}
8185
if (values.profile === "release") {
8286
features.push("info-level");
8387
}

crates/rspack_binding_api/Cargo.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ color-backtrace = ["dep:color-backtrace"]
1616
debug_tool = ["rspack_core/debug_tool"]
1717
plugin = ["rspack_loader_swc/plugin", "rspack_util/plugin"]
1818
sftrace-setup = ["dep:sftrace-setup", "rspack_allocator/sftrace-setup"]
19+
allocative = [
20+
"rspack_util/allocative",
21+
"rspack_collections/allocative",
22+
"rspack_cacheable/allocative",
23+
"rspack_tracing_perfetto/allocative",
24+
]
1925

2026
[dependencies]
2127
anyhow = { workspace = true }
@@ -41,7 +47,8 @@ rspack_tasks = { workspace = true }
4147
rspack_util = { workspace = true }
4248
rspack_workspace = { workspace = true }
4349

44-
rspack_tracing = { workspace = true }
50+
rspack_tracing = { workspace = true }
51+
rspack_tracing_perfetto = { workspace = true }
4552

4653
async-trait = { workspace = true }
4754
cow-utils = { workspace = true }
@@ -120,7 +127,7 @@ tokio = { workspace = true, features = ["rt", "
120127
ustr = { workspace = true }
121128

122129
[package.metadata.cargo-shear]
123-
ignored = ["parking_lot"]
130+
ignored = ["parking_lot", "rspack_tracing_perfetto"]
124131

125132
[target.'cfg(target_family = "wasm")'.dependencies]
126133
# Pin parking_lot version to the same version within the workspace

crates/rspack_cacheable/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ version.workspace = true
1010
noop = []
1111

1212
[dependencies]
13+
allocative = { workspace = true, optional = true }
1314
camino = { workspace = true }
1415
dashmap = { workspace = true }
1516
hashlink = { workspace = true }
@@ -27,3 +28,7 @@ smol_str = { workspace = true }
2728
swc_core = { workspace = true, features = ["ecma_ast"] }
2829
ustr = { workspace = true }
2930
xxhash-rust = { workspace = true, features = ["const_xxh64"] }
31+
32+
[lints.rust.unexpected_cfgs]
33+
level = "warn"
34+
check-cfg = ['cfg(allocative)']

crates/rspack_cacheable/src/with/as_ref_str.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ use std::sync::{Arc, LazyLock};
6969

7070
use dashmap::DashSet;
7171

72+
#[cfg_attr(allocative, allocative::root)]
7273
pub static CACHED_ARC_STR: LazyLock<DashSet<Arc<str>>> = LazyLock::new(Default::default);
74+
7375
impl AsRefStrConverter for Arc<str> {
7476
fn as_str(&self) -> &str {
7577
self.as_ref()

crates/rspack_collections/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ rayon = { workspace = true }
1616
rspack_cacheable = { workspace = true }
1717
serde = { workspace = true, features = ["derive"] }
1818
ustr = { workspace = true, features = ["serde"] }
19+
allocative = { workspace = true, optional = true }
20+
21+
[lints.rust.unexpected_cfgs]
22+
level = "warn"
23+
check-cfg = ['cfg(allocative)']
24+

crates/rspack_collections/src/identifier.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub type IdentifierLinkedSet = LinkedHashSet<Identifier, BuildHasherDefault<Iden
3636

3737
#[cacheable(hashable)]
3838
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize)]
39+
#[cfg_attr(allocative, derive(allocative::Allocative))]
3940
pub struct Identifier(#[cacheable(with=AsPreset)] Ustr);
4041

4142
impl Deref for Identifier {

crates/rspack_collections/src/ukey.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub trait ItemUkey {
3535
/// Ukey stands for Unique key
3636
#[rspack_cacheable::cacheable]
3737
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
38+
#[cfg_attr(allocative, derive(allocative::Allocative))]
3839
pub struct Ukey(u32);
3940

4041
impl Ukey {

0 commit comments

Comments
 (0)