Skip to content

Support allocative with features = ["allocative"]#340

Open
cormacrelf wants to merge 1 commit intoRoaringBitmap:mainfrom
cormacrelf:allocative
Open

Support allocative with features = ["allocative"]#340
cormacrelf wants to merge 1 commit intoRoaringBitmap:mainfrom
cormacrelf:allocative

Conversation

@cormacrelf
Copy link
Contributor

@cormacrelf cormacrelf commented Nov 27, 2025

Allocative is a trait (see https://docs.rs/allocative) that lets you profile allocations. This gives you insight similar to RoaringBitmap::statistics(), but built-in to larger allocative traces of arbitrary data structures.

This just derives allocative on all the container types and anything within them, doesn't need anything fancy.

This is what you get:

Screenshot from 2025-11-27 11 55 50

Allocative is a trait that lets you trace allocations.
This gives you insight similar to `RoaringBitmap::statistics()`, but
built-in to larger allocative traces of arbitrary data structures.
Copy link
Member

@Kerollmops Kerollmops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cormacrelf 👋

Thank you very much for the addition. Looks actually really cool. Could you talk about these flamegraphs, how to use them in the README, and rebase this branch on main, please?

Have a nide day 🌵

Comment on lines +10 to +50
#[test]
fn flamegraph_bitmap() {
let mut foo1 = RoaringBitmap::new();
foo1.insert_range(0..1_000_000);
foo1.insert(2_000_000);
foo1.insert(9_000_000);

let mut flamegraph = FlameGraphBuilder::default();
flamegraph.visit_root(&foo1);
let flamegraph_src = flamegraph.finish().flamegraph().write();
let mut f = File::create("../target/bitmap.folded").unwrap();
write!(f, "{}", flamegraph_src).unwrap();

/*
cargo test -p roaring --features allocative --test allocative
inferno-flamegraph target/bitmap.folded > target/bitmap.flamegraph.svg
open target/bitmap.flamegraph.svg
*/
}

#[test]
fn flamegraph_treemap() {
let mut foo1 = RoaringTreemap::new();
foo1.insert_range(0..1_000_000);
foo1.insert(2_000_000);
foo1.insert(9_000_000);
foo1.insert((1 << 32) + 9000);
foo1.insert((2 << 32) + 9000);

let mut flamegraph = FlameGraphBuilder::default();
flamegraph.visit_root(&foo1);
let flamegraph_src = flamegraph.finish().flamegraph().write();
let mut f = File::create("../target/treemap.folded").unwrap();
write!(f, "{}", flamegraph_src).unwrap();

/*
cargo test -p roaring --features allocative --test allocative
inferno-flamegraph target/treemap.folded > target/treemap.flamegraph.svg
open target/treemap.flamegraph.svg
*/
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these would be better as examples than tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants