Skip to content

Commit

Permalink
Add a test of memory use when logging a lot of big images (#1372)
Browse files Browse the repository at this point in the history
* Add a test of memory use when logging a lot of big images

* copy-pasta

Co-authored-by: Clement Rey <[email protected]>

* copy-pasta

Co-authored-by: Clement Rey <[email protected]>

* Add store archiving to the stack shortening

* fix feature name

---------

Co-authored-by: Clement Rey <[email protected]>
  • Loading branch information
emilk and teh-cmc authored Feb 22, 2023
1 parent 0bc2e89 commit 6b9aab0
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[workspace]
resolver = "2"
members = ["crates/*", "examples/rust/*", "rerun_py", "run_wasm"]
members = [
"crates/*",
"examples/rust/*",
"rerun_py",
"run_wasm",
"tests/rust/*",
]

[workspace.package]
authors = ["rerun.io <[email protected]>"]
Expand Down Expand Up @@ -55,6 +61,7 @@ half = "2.0"
image = "0.24"
lazy_static = "1.4"
macaw = "0.18"
mimalloc = "0.1.29"
ndarray = "0.15"
polars-core = "0.27.1"
polars-lazy = "0.27.1"
Expand Down
2 changes: 1 addition & 1 deletion crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ polars-ops = { workspace = true, optional = true, features = [

[dev-dependencies]
criterion = "0.4"
mimalloc = "0.1"
mimalloc.workspace = true
polars-core = { workspace = true, features = [
"diagonal_concat",
"dtype-date",
Expand Down
2 changes: 1 addition & 1 deletion crates/re_data_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ puffin.workspace = true

[dev-dependencies]
criterion = "0.4"
mimalloc = "0.1"
mimalloc.workspace = true
rand = "0.8"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion crates/re_int_histogram/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static_assertions = "1.1"
[dev-dependencies]
criterion = "0.4"
insta = "1.23"
mimalloc = "0.1"
mimalloc.workspace = true


[lib]
Expand Down
2 changes: 1 addition & 1 deletion crates/re_log_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ruzstd = { version = "0.3.0", optional = true } # works on wasm

[dev-dependencies]
criterion = "0.4"
mimalloc = "0.1"
mimalloc.workspace = true
serde_test = { version = "1" }
arrow2 = { workspace = true, features = [
"io_ipc",
Expand Down
2 changes: 1 addition & 1 deletion crates/re_query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ polars-core = { workspace = true, optional = true, features = [
[dev-dependencies]
criterion = "0.4"
itertools = "0.10"
mimalloc = "0.1"
mimalloc.workspace = true
polars-core = { workspace = true, features = [
"dtype-date",
"dtype-time",
Expand Down
3 changes: 3 additions & 0 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ pub mod external {
pub use re_memory;
pub use re_sdk_comms;

#[cfg(feature = "re_viewer")]
pub use re_viewer;

#[cfg(feature = "glam")]
pub use re_log_types::external::glam;

Expand Down
5 changes: 5 additions & 0 deletions crates/re_viewer/src/ui/memory_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ impl MemoryPanel {

fn summarize_callstack(callstack: &str) -> String {
let patterns = [
("MsgSender", "MsgSender"),
("App::receive_messages", "App::receive_messages"),
("w_store::store::ComponentBucket>::archive", "archive"),
("DataStore>::insert", "DataStore"),
("LogDb", "LogDb"),
("EntityDb", "EntityDb"),
("EntityTree", "EntityTree"),
("::LogMsg>::deserialize", "LogMsg"),
("::TimePoint>::deserialize", "TimePoint"),
("ImageCache", "ImageCache"),
("gltf", "gltf"),
("image::image", "image"),
// -----
Expand Down
2 changes: 1 addition & 1 deletion crates/rerun/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ webbrowser = { version = "0.8", optional = true }
# Native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { workspace = true, features = ["derive"] }
mimalloc = "0.1.29"
mimalloc.workspace = true
puffin_http = "0.11"
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

Expand Down
2 changes: 2 additions & 0 deletions crates/rerun/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use re_smart_channel::Receiver;
use anyhow::Context as _;
use clap::Subcommand;

// Note the extra blank lines between the point-lists below: it is required by `clap`.

/// The Rerun Viewer and Server
///
/// Features:
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/raw_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ anyhow.workspace = true
bytes = "1.3"
clap = { workspace = true, features = ["derive"] }
gltf.workspace = true
mimalloc = "0.1"
mimalloc.workspace = true
reqwest = { workspace = true, features = ["blocking", "rustls-tls"] }
2 changes: 1 addition & 1 deletion rerun_py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ image = { version = "0.24", default-features = false, features = [
] }
itertools = "0.10"
macaw.workspace = true
mimalloc = { version = "0.1.29", features = ["local_dynamic_tls"] }
mimalloc = { workspace = true, features = ["local_dynamic_tls"] }
numpy = { version = "0.18.0", features = ["half"] }
pyo3 = { version = "0.18.0", features = ["abi3-py38"] }
rand = { version = "0.8", features = ["std_rng"] }
Expand Down
1 change: 1 addition & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Uses of the rerun SDK designed to test different things.
13 changes: 13 additions & 0 deletions tests/rust/test_image_memory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "test_image_memory"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish = false

[dependencies]
rerun.workspace = true
re_format.workspace = true

mimalloc.workspace = true
56 changes: 56 additions & 0 deletions tests/rust/test_image_memory/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Logs a bunch of big images to test Rerun memory usage.

use mimalloc::MiMalloc;
use re_memory::AccountingAllocator;
use rerun::external::{image, re_memory, re_viewer};

#[global_allocator]
static GLOBAL: AccountingAllocator<MiMalloc> = AccountingAllocator::new(MiMalloc);

fn main() -> Result<(), Box<dyn std::error::Error>> {
re_memory::accounting_allocator::turn_on_tracking_if_env_var(
re_viewer::env_vars::RERUN_TRACK_ALLOCATIONS,
);

let session = rerun::Session::init("test_image_memory_rs", true);

session.spawn(|mut session| {
log_images(&mut session).unwrap();
})?;

Ok(())
}

fn log_images(session: &mut rerun::Session) -> Result<(), Box<dyn std::error::Error>> {
let (w, h) = (2048, 1024);
let n = 100;

let image = image::RgbaImage::from_fn(w, h, |x, y| {
if (x + y) % 2 == 0 {
image::Rgba([0, 0, 0, 255])
} else {
image::Rgba([255, 255, 255, 255])
}
});
let tensor = rerun::components::Tensor::from_image(image)?;

for _ in 0..n {
rerun::MsgSender::new("image")
.with_component(&[tensor.clone()])?
.send(session)?;
}

eprintln!(
"Logged {n} {w}x{h} RGBA images = {}",
re_format::format_bytes((n * w * h * 4) as _)
);

// Give viewer time to load it:
std::thread::sleep(std::time::Duration::from_secs(2));

if let Some(allocs) = re_memory::accounting_allocator::global_allocs() {
eprintln!("{} RAM used", re_format::format_bytes(allocs.size as _));
}

Ok(())
}

1 comment on commit 6b9aab0

@github-actions
Copy link

Choose a reason for hiding this comment

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

Rust Benchmark

Benchmark suite Current: 6b9aab0 Previous: 0bc2e89 Ratio
datastore/insert/batch/rects/insert 550921 ns/iter (± 3261) 560773 ns/iter (± 1724) 0.98
datastore/latest_at/batch/rects/query 1827 ns/iter (± 6) 1805 ns/iter (± 28) 1.01
datastore/latest_at/missing_components/primary 356 ns/iter (± 2) 357 ns/iter (± 0) 1.00
datastore/latest_at/missing_components/secondaries 425 ns/iter (± 14) 425 ns/iter (± 0) 1
datastore/range/batch/rects/query 150015 ns/iter (± 510) 150127 ns/iter (± 234) 1.00
mono_points_arrow/generate_message_bundles 47286805 ns/iter (± 983856) 53231303 ns/iter (± 609706) 0.89
mono_points_arrow/generate_messages 125737059 ns/iter (± 1096303) 139356081 ns/iter (± 1459025) 0.90
mono_points_arrow/encode_log_msg 153199409 ns/iter (± 939772) 173224585 ns/iter (± 2468141) 0.88
mono_points_arrow/encode_total 327214877 ns/iter (± 1488287) 369964000 ns/iter (± 3903155) 0.88
mono_points_arrow/decode_log_msg 176399062 ns/iter (± 777294) 190135352 ns/iter (± 1428624) 0.93
mono_points_arrow/decode_message_bundles 64556734 ns/iter (± 766064) 77249933 ns/iter (± 1168466) 0.84
mono_points_arrow/decode_total 238830646 ns/iter (± 1386896) 269983640 ns/iter (± 2093104) 0.88
batch_points_arrow/generate_message_bundles 323961 ns/iter (± 2533) 324793 ns/iter (± 879) 1.00
batch_points_arrow/generate_messages 6346 ns/iter (± 39) 6404 ns/iter (± 14) 0.99
batch_points_arrow/encode_log_msg 365663 ns/iter (± 2095) 373777 ns/iter (± 3057) 0.98
batch_points_arrow/encode_total 713250 ns/iter (± 4746) 726038 ns/iter (± 2838) 0.98
batch_points_arrow/decode_log_msg 348663 ns/iter (± 1182) 349642 ns/iter (± 1427) 1.00
batch_points_arrow/decode_message_bundles 2080 ns/iter (± 14) 2128 ns/iter (± 5) 0.98
batch_points_arrow/decode_total 355260 ns/iter (± 1495) 361712 ns/iter (± 2120) 0.98
arrow_mono_points/insert 6107628644 ns/iter (± 12499650) 7471020932 ns/iter (± 177013735) 0.82
arrow_mono_points/query 1726227 ns/iter (± 14526) 1780967 ns/iter (± 14889) 0.97
arrow_batch_points/insert 2691302 ns/iter (± 18310) 2713162 ns/iter (± 31137) 0.99
arrow_batch_points/query 16806 ns/iter (± 109) 16846 ns/iter (± 36) 1.00
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.