From 26639e9c8c95dca59d73a2d4b6e17eb286d82bc3 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 23 May 2022 17:10:09 +0200 Subject: [PATCH] Fast data access prototype (#7) A new data store which is homogeneous (same type at each type path) and supports batching for fast logging of a lot of data. --- .vscode/launch.json | 18 + Cargo.lock | 301 ++++++++++++++- Cargo.toml | 8 + deny.toml | 1 + prototype/Cargo.toml | 23 ++ prototype/benches/data_benchmark.rs | 149 ++++++++ prototype/examples/memory_usage.rs | 188 ++++++++++ prototype/src/lib.rs | 280 ++++++++++++++ prototype/src/scene.rs | 40 ++ prototype/src/storage.rs | 434 ++++++++++++++++++++++ prototype/tests/test_data_store.rs | 557 ++++++++++++++++++++++++++++ 11 files changed, 1993 insertions(+), 6 deletions(-) create mode 100644 prototype/Cargo.toml create mode 100644 prototype/benches/data_benchmark.rs create mode 100644 prototype/examples/memory_usage.rs create mode 100644 prototype/src/lib.rs create mode 100644 prototype/src/scene.rs create mode 100644 prototype/src/storage.rs create mode 100644 prototype/tests/test_data_store.rs diff --git a/.vscode/launch.json b/.vscode/launch.json index 282bd5c7f86b..307d5919fa26 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,5 +42,23 @@ ], "cwd": "${workspaceFolder}" }, + { + "name": "Debug 'prototype' tests", + "type": "lldb", + "request": "launch", + "cargo": { + "args": [ + "test", + "--no-run", + "--package=prototype" + ], + "filter": { + "name": "prototype", + "kind": "lib" + } + }, + "args": [], + "cwd": "${workspaceFolder}" + }, ] } diff --git a/Cargo.lock b/Cargo.lock index c3d05b997e5a..8de0c3b38cb1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -181,6 +181,15 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitmaps" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" +dependencies = [ + "typenum", +] + [[package]] name = "block" version = "0.1.6" @@ -196,6 +205,18 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.9.1" @@ -254,6 +275,15 @@ dependencies = [ "nix", ] +[[package]] +name = "cast" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" +dependencies = [ + "rustc_version", +] + [[package]] name = "cc" version = "1.0.73" @@ -325,6 +355,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "bitflags", + "textwrap 0.11.0", + "unicode-width", +] + [[package]] name = "clap" version = "3.1.17" @@ -339,7 +380,7 @@ dependencies = [ "lazy_static", "strsim", "termcolor", - "textwrap", + "textwrap 0.15.0", ] [[package]] @@ -558,6 +599,42 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "criterion" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +dependencies = [ + "atty", + "cast", + "clap 2.34.0", + "criterion-plot", + "csv", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_cbor", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.4" @@ -568,6 +645,31 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if 1.0.0", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + [[package]] name = "crossbeam-utils" version = "0.8.8" @@ -588,6 +690,28 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa 0.4.8", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "cty" version = "0.2.2" @@ -1305,7 +1429,7 @@ checksum = "ff8670570af52249509a86f5e3e18a08c60b177071826898fde8997cf5f6bfbb" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 1.0.1", ] [[package]] @@ -1346,7 +1470,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 1.0.1", "pin-project-lite", "socket2", "tokio", @@ -1372,6 +1496,20 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "im" +version = "15.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" +dependencies = [ + "bitmaps", + "rand_core", + "rand_xoshiro", + "sized-chunks", + "typenum", + "version_check", +] + [[package]] name = "image" version = "0.23.14" @@ -1428,6 +1566,12 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.1" @@ -1911,7 +2055,7 @@ name = "objectron" version = "0.1.0" dependencies = [ "anyhow", - "clap", + "clap 3.1.17", "comms", "glam", "image", @@ -1934,6 +2078,12 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "os_str_bytes" version = "6.0.0" @@ -2058,6 +2208,34 @@ version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" +[[package]] +name = "plotters" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" + +[[package]] +name = "plotters-svg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +dependencies = [ + "plotters-backend", +] + [[package]] name = "png" version = "0.16.8" @@ -2174,6 +2352,18 @@ dependencies = [ "prost", ] +[[package]] +name = "prototype" +version = "0.1.0" +dependencies = [ + "ahash", + "criterion", + "im", + "mimalloc", + "nohash-hasher", + "tracing", +] + [[package]] name = "puffin" version = "0.13.1" @@ -2241,6 +2431,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rand_xoshiro" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" +dependencies = [ + "rand_core", +] + [[package]] name = "raw-window-handle" version = "0.4.3" @@ -2250,6 +2449,30 @@ dependencies = [ "cty", ] +[[package]] +name = "rayon" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + [[package]] name = "redox_syscall" version = "0.2.13" @@ -2279,6 +2502,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.25" @@ -2366,6 +2595,15 @@ dependencies = [ "serde", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "rustls" version = "0.20.4" @@ -2431,6 +2669,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "semver" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" + [[package]] name = "serde" version = "1.0.137" @@ -2440,6 +2684,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.137" @@ -2457,7 +2711,7 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" dependencies = [ - "itoa", + "itoa 1.0.1", "ryu", "serde", ] @@ -2492,6 +2746,16 @@ dependencies = [ "libc", ] +[[package]] +name = "sized-chunks" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" +dependencies = [ + "bitmaps", + "typenum", +] + [[package]] name = "slab" version = "0.4.6" @@ -2635,6 +2899,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + [[package]] name = "textwrap" version = "0.15.0" @@ -2711,6 +2984,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -2945,6 +3228,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + [[package]] name = "unicode-xid" version = "0.2.3" @@ -3018,7 +3307,7 @@ dependencies = [ "arboard", "bytemuck", "cgmath", - "clap", + "clap 3.1.17", "comms", "console_error_panic_hook", "eframe", diff --git a/Cargo.toml b/Cargo.toml index b7fb6b4fe21e..977198ac1da1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = [ "comms", "log_types", "objectron", + "prototype", "viewer", "web_server", ] @@ -11,3 +12,10 @@ members = [ [profile.dev] # opt-level = 1 # Speed up debug builds + +[profile.release] +# debug = true # good for profilers + +[profile.bench] +debug = true + diff --git a/deny.toml b/deny.toml index 0fd5b77010e1..04fb112ef498 100644 --- a/deny.toml +++ b/deny.toml @@ -32,6 +32,7 @@ skip = [ { name = "windows_x86_64_msvc" }, # Fix coming in https://github.com/PolyMeilex/rfd/pull/64 ] skip-tree = [ + { name = "criterion" }, # dev-dependency { name = "winit" }, # winit pulls in a lot of old, duplicated crates. at least it is not wasm ] diff --git a/prototype/Cargo.toml b/prototype/Cargo.toml new file mode 100644 index 000000000000..6a04779d1412 --- /dev/null +++ b/prototype/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "prototype" +version = "0.1.0" +edition = "2021" +rust-version = "1.60" +license = "MIT OR Apache-2.0" +publish = false + + +[dependencies] +ahash = "0.7" +im = "15" +mimalloc = "0.1" +nohash-hasher = "0.2" +tracing = "0.1" + +[dev-dependencies] +criterion = "0.3" + + +[[bench]] +name = "data_benchmark" +harness = false diff --git a/prototype/benches/data_benchmark.rs b/prototype/benches/data_benchmark.rs new file mode 100644 index 000000000000..93f438418fe7 --- /dev/null +++ b/prototype/benches/data_benchmark.rs @@ -0,0 +1,149 @@ +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + +use criterion::{criterion_group, criterion_main, Criterion}; +use prototype::TypePathDataStore; +use prototype::*; + +use std::sync::Arc; + +const NUM_FRAMES: i64 = 1_000; // this can have a big impact on performance +const NUM_POINTS_PER_CAMERA: u64 = 1_000; +const TOTAL_POINTS: u64 = 2 * NUM_POINTS_PER_CAMERA; + +fn data_path(camera: &str, index: u64, field: &str) -> DataPath { + im::vector![ + DataPathComponent::Name("camera".into()), + DataPathComponent::Index(Index::String(camera.into())), + DataPathComponent::Name("point".into()), + DataPathComponent::Index(Index::Sequence(index)), + DataPathComponent::Name(field.into()), + ] +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] +struct Time(i64); + +fn generate_date(individual_pos: bool, individual_radius: bool) -> TypePathDataStore