From 49acf64de49da21b2ea88aaf478f18212d06e405 Mon Sep 17 00:00:00 2001 From: Taj Pereira Date: Thu, 1 Jan 2026 06:47:42 +1030 Subject: [PATCH 1/3] Add DHAT to vello cpu example --- Cargo.lock | 86 ++++++++++++++++++- Cargo.toml | 5 ++ .../vello_cpu/examples/winit/Cargo.toml | 4 + .../vello_cpu/examples/winit/README.md | 30 +++++++ .../vello_cpu/examples/winit/src/main.rs | 7 ++ 5 files changed, 130 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9565b1c61..3d61e1601 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -732,6 +732,7 @@ dependencies = [ "num-traits", "once_cell", "oorandom", + "plotters", "regex", "serde", "serde_derive", @@ -814,6 +815,22 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edf215dbb8cb1409cca7645aaed35f9e39fb0a21855bba1ac48bc0334903bf66" +[[package]] +name = "dhat" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot", + "rustc-hash 1.1.0", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1844,6 +1861,22 @@ dependencies = [ "libc", ] +[[package]] +name = "kurbo" +version = "0.6.0" +dependencies = [ + "arrayvec", + "criterion", + "euclid", + "getrandom", + "libm", + "mint", + "rand", + "schemars", + "serde", + "smallvec", +] + [[package]] name = "kurbo" version = "0.11.3" @@ -1864,7 +1897,6 @@ dependencies = [ "arrayvec", "euclid", "libm", - "schemars", "smallvec", ] @@ -2076,6 +2108,18 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mint" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" + +[[package]] +name = "mintex" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c505b3e17ed6b70a7ed2e67fbb2c560ee327353556120d6e72f5232b6880d536" + [[package]] name = "mio" version = "1.0.4" @@ -2712,6 +2756,34 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "png" version = "0.17.16" @@ -3353,6 +3425,9 @@ name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +dependencies = [ + "serde", +] [[package]] name = "smithay-client-toolkit" @@ -3584,6 +3659,12 @@ dependencies = [ "syn", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "thread_local" version = "1.1.9" @@ -3987,6 +4068,7 @@ dependencies = [ name = "vello_cpu_winit" version = "0.0.0" dependencies = [ + "dhat", "softbuffer", "vello_common", "vello_cpu", @@ -5203,7 +5285,7 @@ dependencies = [ "env_logger", "getrandom", "jni", - "kurbo 0.12.0", + "kurbo 0.6.0", "log", "notify-debouncer-full", "pollster", diff --git a/Cargo.toml b/Cargo.toml index adaf04439..7ac83508d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -156,3 +156,8 @@ syn = { version = "2.0.101", features = ["full", "extra-traits"] } quote = "1.0.40" serde = { version = "1.0.225", default-features = false } serde_json = "1.0.145" + +# Profiling profile: release optimizations with debug info for better backtraces. +[profile.profiling] +inherits = "release" +debug = 1 diff --git a/sparse_strips/vello_cpu/examples/winit/Cargo.toml b/sparse_strips/vello_cpu/examples/winit/Cargo.toml index b3d331f2f..f9396bd91 100644 --- a/sparse_strips/vello_cpu/examples/winit/Cargo.toml +++ b/sparse_strips/vello_cpu/examples/winit/Cargo.toml @@ -9,9 +9,13 @@ publish = false [lints] workspace = true +[features] +dhat-heap = ["dep:dhat"] + [dependencies] winit = { workspace = true } vello_common = { workspace = true } vello_cpu = { workspace = true, features = ["multithreading"] } vello_example_scenes = { workspace = true, features = ["cpu"] } softbuffer = "0.4.6" +dhat = { version = "0.3.3", optional = true } diff --git a/sparse_strips/vello_cpu/examples/winit/README.md b/sparse_strips/vello_cpu/examples/winit/README.md index 2434f4dd1..5cca49e71 100644 --- a/sparse_strips/vello_cpu/examples/winit/README.md +++ b/sparse_strips/vello_cpu/examples/winit/README.md @@ -37,3 +37,33 @@ This example uses multi-threaded CPU rendering. The number of threads used is de For better performance, always run with the `--release` flag. +## Heap Profiling with DHAT + +This example supports heap profiling using the [dhat](https://docs.rs/dhat) crate. This is useful for analyzing memory allocation patterns and identifying allocation hotspots. + +### Running with Heap Profiling + +```sh +cargo run -p vello_cpu_winit --profile profiling --features dhat-heap +``` + +The program will run slower than normal due to allocation tracking. + +When you exit the application, you'll see a summary like: + +``` +dhat: Total: 1,256 bytes in 6 blocks +dhat: At t-gmax: 1,256 bytes in 6 blocks +dhat: At t-end: 1,256 bytes in 6 blocks +dhat: The data has been saved to dhat-heap.json, and is viewable with dhat/dh_view.html +``` + +### Viewing Results + +Open the generated `dhat-heap.json` file in [DHAT's online viewer](https://nnethercote.github.io/dh_view/dh_view.html) to explore: + +- Total allocations and their call sites +- Peak heap usage (t-gmax) +- Memory still allocated at exit (t-end) +- Allocation hotspots with full backtraces + diff --git a/sparse_strips/vello_cpu/examples/winit/src/main.rs b/sparse_strips/vello_cpu/examples/winit/src/main.rs index 093c2a9aa..f864ed3f1 100644 --- a/sparse_strips/vello_cpu/examples/winit/src/main.rs +++ b/sparse_strips/vello_cpu/examples/winit/src/main.rs @@ -8,6 +8,10 @@ reason = "truncation has no appreciable impact in this demo" )] +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + #[cfg(not(target_arch = "wasm32"))] use std::env; use std::num::NonZeroU32; @@ -55,6 +59,9 @@ struct App { } fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + #[cfg(not(target_arch = "wasm32"))] let (scenes, start_scene_index) = { let mut start_scene_index = 0; From 6dbbc533cee91e2a88c0280a8967dc5f1da39132 Mon Sep 17 00:00:00 2001 From: Taj Pereira Date: Thu, 1 Jan 2026 07:02:13 +1030 Subject: [PATCH 2/3] Apply suggestion from @taj-p --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7ac83508d..607bc9a4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -157,7 +157,7 @@ quote = "1.0.40" serde = { version = "1.0.225", default-features = false } serde_json = "1.0.145" -# Profiling profile: release optimizations with debug info for better backtraces. +# Profiling profile: release optimizations with debug info for demangled backtraces. [profile.profiling] inherits = "release" debug = 1 From 281f8730cdfe4043201c058bfe337cd74d09b73a Mon Sep 17 00:00:00 2001 From: Taj Pereira Date: Thu, 1 Jan 2026 07:14:10 +1030 Subject: [PATCH 3/3] . --- Cargo.lock | 57 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d61e1601..394b309e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -732,7 +732,6 @@ dependencies = [ "num-traits", "once_cell", "oorandom", - "plotters", "regex", "serde", "serde_derive", @@ -1861,22 +1860,6 @@ dependencies = [ "libc", ] -[[package]] -name = "kurbo" -version = "0.6.0" -dependencies = [ - "arrayvec", - "criterion", - "euclid", - "getrandom", - "libm", - "mint", - "rand", - "schemars", - "serde", - "smallvec", -] - [[package]] name = "kurbo" version = "0.11.3" @@ -1897,6 +1880,7 @@ dependencies = [ "arrayvec", "euclid", "libm", + "schemars", "smallvec", ] @@ -2108,12 +2092,6 @@ dependencies = [ "simd-adler32", ] -[[package]] -name = "mint" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" - [[package]] name = "mintex" version = "0.1.4" @@ -2756,34 +2734,6 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" -[[package]] -name = "plotters" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" - -[[package]] -name = "plotters-svg" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" -dependencies = [ - "plotters-backend", -] - [[package]] name = "png" version = "0.17.16" @@ -3425,9 +3375,6 @@ name = "smallvec" version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" -dependencies = [ - "serde", -] [[package]] name = "smithay-client-toolkit" @@ -5285,7 +5232,7 @@ dependencies = [ "env_logger", "getrandom", "jni", - "kurbo 0.6.0", + "kurbo 0.12.0", "log", "notify-debouncer-full", "pollster",