Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce StoreHub and rename Recording->Store #2301

Merged
merged 19 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions crates/re_data_store/examples/memory_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn live_bytes() -> usize {

// ----------------------------------------------------------------------------

use re_log_types::{entity_path, DataRow, RecordingId, RecordingType, RowId};
use re_log_types::{entity_path, DataRow, RowId, StoreId, StoreKind};

fn main() {
log_messages();
Expand Down Expand Up @@ -91,7 +91,7 @@ fn log_messages() {

const NUM_POINTS: usize = 1_000;

let recording_id = RecordingId::random(RecordingType::Data);
let store_id = StoreId::random(StoreKind::Recording);
let timeline = Timeline::new_sequence("frame_nr");
let mut time_point = TimePoint::default();
time_point.insert(timeline, TimeInt::from(0));
Expand All @@ -118,7 +118,7 @@ fn log_messages() {
);
let table_bytes = live_bytes() - used_bytes_start;
let log_msg = Box::new(LogMsg::ArrowMsg(
recording_id.clone(),
store_id.clone(),
table.to_arrow_msg().unwrap(),
));
let log_msg_bytes = live_bytes() - used_bytes_start;
Expand All @@ -143,10 +143,7 @@ fn log_messages() {
.into_table(),
);
let table_bytes = live_bytes() - used_bytes_start;
let log_msg = Box::new(LogMsg::ArrowMsg(
recording_id,
table.to_arrow_msg().unwrap(),
));
let log_msg = Box::new(LogMsg::ArrowMsg(store_id, table.to_arrow_msg().unwrap()));
let log_msg_bytes = live_bytes() - used_bytes_start;
println!("Arrow payload containing a Pos2 uses {table_bytes} bytes in RAM");
let encoded = encode_log_msg(&log_msg);
Expand Down
30 changes: 18 additions & 12 deletions crates/re_data_store/src/log_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use nohash_hasher::IntMap;

use re_arrow_store::{DataStoreConfig, TimeInt};
use re_log_types::{
ArrowMsg, Component as _, ComponentPath, DataCell, DataRow, DataTable, EntityPath,
EntityPathHash, EntityPathOpMsg, InstanceKey, LogMsg, PathOp, RecordingId, RecordingInfo,
RecordingType, RowId, SetRecordingInfo, TimePoint, Timeline,
ApplicationId, ArrowMsg, Component as _, ComponentPath, DataCell, DataRow, DataTable,
EntityPath, EntityPathHash, EntityPathOpMsg, InstanceKey, LogMsg, PathOp, RecordingInfo, RowId,
SetRecordingInfo, StoreId, StoreKind, TimePoint, Timeline,
};

use crate::{Error, TimesPerTimeline};
Expand Down Expand Up @@ -172,8 +172,8 @@ impl EntityDb {

/// A in-memory database built from a stream of [`LogMsg`]es.
pub struct LogDb {
/// The [`RecordingId`] for this log.
recording_id: RecordingId,
/// The [`StoreId`] for this log.
store_id: StoreId,

/// All [`EntityPathOpMsg`]s ever received.
entity_op_msgs: BTreeMap<RowId, EntityPathOpMsg>,
Expand All @@ -189,9 +189,9 @@ pub struct LogDb {
}

impl LogDb {
pub fn new(recording_id: RecordingId) -> Self {
pub fn new(store_id: StoreId) -> Self {
Self {
recording_id,
store_id,
entity_op_msgs: Default::default(),
data_source: None,
recording_msg: None,
Expand All @@ -207,12 +207,16 @@ impl LogDb {
self.recording_msg().map(|msg| &msg.info)
}

pub fn recording_type(&self) -> RecordingType {
self.recording_id.variant
pub fn app_id(&self) -> Option<&ApplicationId> {
self.recording_info().map(|ri| &ri.application_id)
}

pub fn recording_id(&self) -> &RecordingId {
&self.recording_id
pub fn store_kind(&self) -> StoreKind {
self.store_id.kind
}

pub fn store_id(&self) -> &StoreId {
&self.store_id
}

pub fn timelines(&self) -> impl ExactSizeIterator<Item = &Timeline> {
Expand All @@ -239,6 +243,8 @@ impl LogDb {
pub fn add(&mut self, msg: &LogMsg) -> Result<(), Error> {
re_tracing::profile_function!();

debug_assert_eq!(msg.store_id(), self.store_id());

match &msg {
LogMsg::SetRecordingInfo(msg) => self.add_begin_recording_msg(msg),
LogMsg::EntityPathOpMsg(_, msg) => {
Expand Down Expand Up @@ -287,7 +293,7 @@ impl LogDb {
let cutoff_times = self.entity_db.data_store.oldest_time_per_timeline();

let Self {
recording_id: _,
store_id: _,
entity_op_msgs,
data_source: _,
recording_msg: _,
Expand Down
8 changes: 4 additions & 4 deletions crates/re_data_ui/src/log_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ impl DataUi for SetRecordingInfo {
let SetRecordingInfo { row_id: _, info } = self;
emilk marked this conversation as resolved.
Show resolved Hide resolved
let RecordingInfo {
application_id,
recording_id,
store_id,
started,
recording_source,
is_official_example,
recording_type,
store_kind: recording_type,
} = info;

egui::Grid::new("fields").num_columns(2).show(ui, |ui| {
ui.monospace("application_id:");
ui.label(application_id.to_string());
ui.end_row();

ui.monospace("recording_id:");
ui.label(format!("{recording_id:?}"));
ui.monospace("store_id:");
ui.label(format!("{store_id:?}"));
ui.end_row();

ui.monospace("started:");
Expand Down
30 changes: 15 additions & 15 deletions crates/re_log_encoding/benches/msg_encode_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
use re_components::datagen::{build_frame_nr, build_some_colors, build_some_point2d};

use re_log_types::{
entity_path, DataRow, DataTable, Index, LogMsg, RecordingId, RecordingType, RowId, TableId,
entity_path, DataRow, DataTable, Index, LogMsg, RowId, StoreId, StoreKind, TableId,
};

use criterion::{criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -44,10 +44,10 @@ fn decode_log_msgs(mut bytes: &[u8]) -> Vec<LogMsg> {
messages
}

fn generate_messages(recording_id: &RecordingId, tables: &[DataTable]) -> Vec<LogMsg> {
fn generate_messages(store_id: &StoreId, tables: &[DataTable]) -> Vec<LogMsg> {
tables
.iter()
.map(|table| LogMsg::ArrowMsg(recording_id.clone(), table.to_arrow_msg().unwrap()))
.map(|table| LogMsg::ArrowMsg(store_id.clone(), table.to_arrow_msg().unwrap()))
.collect()
}

Expand Down Expand Up @@ -83,22 +83,22 @@ fn mono_points_arrow(c: &mut Criterion) {
}

{
let recording_id = RecordingId::random(RecordingType::Data);
let store_id = StoreId::random(StoreKind::Recording);
let mut group = c.benchmark_group("mono_points_arrow");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("generate_message_bundles", |b| {
b.iter(generate_tables);
});
let tables = generate_tables();
group.bench_function("generate_messages", |b| {
b.iter(|| generate_messages(&recording_id, &tables));
b.iter(|| generate_messages(&store_id, &tables));
});
let messages = generate_messages(&recording_id, &tables);
let messages = generate_messages(&store_id, &tables);
group.bench_function("encode_log_msg", |b| {
b.iter(|| encode_log_msgs(&messages));
});
group.bench_function("encode_total", |b| {
b.iter(|| encode_log_msgs(&generate_messages(&recording_id, &generate_tables())));
b.iter(|| encode_log_msgs(&generate_messages(&store_id, &generate_tables())));
});

let encoded = encode_log_msgs(&messages);
Expand Down Expand Up @@ -139,22 +139,22 @@ fn mono_points_arrow_batched(c: &mut Criterion) {
}

{
let recording_id = RecordingId::random(RecordingType::Data);
let store_id = StoreId::random(StoreKind::Recording);
let mut group = c.benchmark_group("mono_points_arrow_batched");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("generate_message_bundles", |b| {
b.iter(generate_table);
});
let tables = [generate_table()];
group.bench_function("generate_messages", |b| {
b.iter(|| generate_messages(&recording_id, &tables));
b.iter(|| generate_messages(&store_id, &tables));
});
let messages = generate_messages(&recording_id, &tables);
let messages = generate_messages(&store_id, &tables);
group.bench_function("encode_log_msg", |b| {
b.iter(|| encode_log_msgs(&messages));
});
group.bench_function("encode_total", |b| {
b.iter(|| encode_log_msgs(&generate_messages(&recording_id, &[generate_table()])));
b.iter(|| encode_log_msgs(&generate_messages(&store_id, &[generate_table()])));
});

let encoded = encode_log_msgs(&messages);
Expand Down Expand Up @@ -196,22 +196,22 @@ fn batch_points_arrow(c: &mut Criterion) {
}

{
let recording_id = RecordingId::random(RecordingType::Data);
let store_id = StoreId::random(StoreKind::Recording);
let mut group = c.benchmark_group("batch_points_arrow");
group.throughput(criterion::Throughput::Elements(NUM_POINTS as _));
group.bench_function("generate_message_bundles", |b| {
b.iter(generate_tables);
});
let tables = generate_tables();
group.bench_function("generate_messages", |b| {
b.iter(|| generate_messages(&recording_id, &tables));
b.iter(|| generate_messages(&store_id, &tables));
});
let messages = generate_messages(&recording_id, &tables);
let messages = generate_messages(&store_id, &tables);
group.bench_function("encode_log_msg", |b| {
b.iter(|| encode_log_msgs(&messages));
});
group.bench_function("encode_total", |b| {
b.iter(|| encode_log_msgs(&generate_messages(&recording_id, &generate_tables())));
b.iter(|| encode_log_msgs(&generate_messages(&store_id, &generate_tables())));
});

let encoded = encode_log_msgs(&messages);
Expand Down
8 changes: 4 additions & 4 deletions crates/re_log_encoding/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,22 @@ impl<R: std::io::Read> Iterator for Decoder<R> {
#[test]
fn test_encode_decode() {
use re_log_types::{
ApplicationId, LogMsg, RecordingId, RecordingInfo, RecordingSource, RecordingType, RowId,
SetRecordingInfo, Time,
ApplicationId, LogMsg, RecordingInfo, RecordingSource, RowId, SetRecordingInfo, StoreId,
StoreKind, Time,
};

let messages = vec![LogMsg::SetRecordingInfo(SetRecordingInfo {
row_id: RowId::random(),
info: RecordingInfo {
application_id: ApplicationId("test".to_owned()),
recording_id: RecordingId::random(RecordingType::Data),
store_id: StoreId::random(StoreKind::Recording),
is_official_example: true,
started: Time::now(),
recording_source: RecordingSource::RustSdk {
rustc_version: String::new(),
llvm_version: String::new(),
},
recording_type: re_log_types::RecordingType::Data,
store_kind: re_log_types::StoreKind::Recording,
},
})];

Expand Down
Loading