Skip to content

Commit

Permalink
Reduce rerun_c library size (by depending on fewer unnecessary crates) (
Browse files Browse the repository at this point in the history
#4147)

### What

* Fix #2905 
   * reduces Rerun C size from 41.0MiB to 34.2MiB (MacOS aarch64)
* feels like there's more we should be able to do, but this PR stops the
bleed of having it become larger as we add new types!
* note that since this is a static library, typically the actual
stripping occurs when linking the final binary, so while it's great that
our library gets smaller for many reasons, it's not _critical_
* `re_log_types` no longer depends on `re_types`
* `re_sdk` no longer depends on `re_memory`
* `re_sdk` no longer depends on `re_types`
   * things only come together now on `rerun` crate


Dependency graph before:

![deps-old](https://github.com/rerun-io/rerun/assets/1220815/8013eccc-6c8b-406e-a821-756d8dab31d7)

Dependency graph now:

![deps-new](https://github.com/rerun-io/rerun/assets/1220815/b1fc5aae-8329-49d5-a059-1c93f39addd5)

Graphs via: `cargo depgraph --all-deps --workspace-only --all-features
--dedup-transitive-deps | dot -Tpng > deps.png`
Rerun C checks via: `cargo build -p rerun_c --release && ls -l
target/release/librerun_c.a`

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4147) (if
applicable)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG

- [PR Build Summary](https://build.rerun.io/pr/4147)
- [Docs
preview](https://rerun.io/preview/8f3291ee534b1ca6eb4a3e3f4dd968ec44998336/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/8f3291ee534b1ca6eb4a3e3f4dd968ec44998336/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
  • Loading branch information
Wumpf authored Nov 7, 2023
1 parent 86eec25 commit 316bddd
Show file tree
Hide file tree
Showing 30 changed files with 175 additions and 161 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/re_arrow_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ all-features = true
default = []

## Enables access to re_types' test components/datatypes.
testing = ["re_types/testing"]
testing = ["re_log_types/testing", "re_types/testing"]

## Enables `parking_lot`'s deadlock detection background thread.
deadlock_detection = ["parking_lot/deadlock_detection"]
Expand Down
1 change: 1 addition & 0 deletions crates/re_arrow_store/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl DataStore {
/// cargo test -p re_arrow_store -- --nocapture datastore_internal_repr
/// ```
#[test]
#[cfg(test)]
fn datastore_internal_repr() {
use re_log_types::DataTable;
use re_types_core::Loggable as _;
Expand Down
3 changes: 3 additions & 0 deletions crates/re_data_source/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ re_log_types.workspace = true
re_log.workspace = true
re_smart_channel.workspace = true
re_tracing.workspace = true
re_types = { workspace = true, features = ["image"] }
re_ws_comms = { workspace = true, features = ["client"] }

anyhow.workspace = true
image.workspace = true
itertools.workspace = true
rayon.workspace = true
thiserror.workspace = true


[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/re_data_source/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
mod data_source;

mod load_file;
mod load_file_contents;
mod web_sockets;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::DataCell;
use image::{guess_format, ImageFormat};
use re_log_types::{DataCell, DataCellError};

/// Errors from [`data_cells_from_file_path`].
#[derive(thiserror::Error, Debug)]
Expand All @@ -8,7 +9,7 @@ pub enum FromFileError {
FileRead(#[from] std::io::Error),

#[error(transparent)]
DataCellError(#[from] crate::DataCellError),
DataCellError(#[from] DataCellError),

#[error(transparent)]
TensorImageLoad(#[from] re_types::tensor_data::TensorImageLoadError),
Expand Down Expand Up @@ -38,8 +39,7 @@ pub fn data_cells_from_file_path(

match extension.as_str() {
"glb" | "gltf" | "obj" => {
use re_types::archetypes::Asset3D;
use re_types_core::AsComponents as _;
use re_types::{archetypes::Asset3D, AsComponents as _};
let cells: Result<Vec<_>, _> = Asset3D::from_file(file_path)?
// TODO(#3414): this should be a method of `Archetype`
.as_component_batches()
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn data_cells_from_file_path(
}

fn image_indicator_cell() -> DataCell {
use re_types_core::Archetype as _;
use re_types::Archetype as _;
let indicator = re_types::archetypes::Image::indicator();
DataCell::from_arrow(
indicator.name(),
Expand All @@ -96,8 +96,7 @@ pub fn data_cells_from_file_contents(

match extension.as_str() {
"glb" | "gltf" | "obj" => {
use re_types::{archetypes::Asset3D, components::MediaType};
use re_types_core::AsComponents as _;
use re_types::{archetypes::Asset3D, components::MediaType, AsComponents as _};
let cells: Result<Vec<_>, _> =
Asset3D::from_bytes(bytes, MediaType::guess_from_path(file_name))
.as_component_batches()
Expand All @@ -116,11 +115,10 @@ pub fn data_cells_from_file_contents(

// Assume an image (there are so many image formats)
_ => {
let format = if let Some(format) = image::ImageFormat::from_extension(extension) {
let format = if let Some(format) = ImageFormat::from_extension(extension) {
format
} else {
image::guess_format(&bytes)
.map_err(re_types::tensor_data::TensorImageLoadError::from)?
guess_format(&bytes).map_err(re_types::tensor_data::TensorImageLoadError::from)?
};

// Assume an image (there are so many image extensions):
Expand Down
4 changes: 2 additions & 2 deletions crates/re_data_source/src/load_file_contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use re_log_encoding::decoder::VersionPolicy;
use re_log_types::{FileSource, LogMsg};
use re_smart_channel::Sender;

use crate::FileContents;
use crate::{load_file::data_cells_from_file_contents, FileContents};

#[allow(clippy::needless_pass_by_value)] // false positive on some feature flags
pub fn load_file_contents(
Expand Down Expand Up @@ -82,7 +82,7 @@ fn log_msg_from_file_contents(
let FileContents { name, bytes } = file_contents;

let entity_path = re_log_types::EntityPath::from_single_string(name.clone());
let cells = re_log_types::data_cells_from_file_contents(&name, bytes.to_vec())?;
let cells = data_cells_from_file_contents(&name, bytes.to_vec())?;

let num_instances = cells.first().map_or(0, |cell| cell.num_instances());

Expand Down
5 changes: 3 additions & 2 deletions crates/re_data_source/src/load_file_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use anyhow::Context as _;
use re_log_types::{FileSource, LogMsg};
use re_smart_channel::Sender;

use crate::load_file::data_cells_from_file_path;

/// Non-blocking.
#[allow(clippy::needless_pass_by_value)] // false positive on some feature flags
pub fn load_file_path(
Expand Down Expand Up @@ -76,7 +78,7 @@ fn log_msg_from_file_path(
file_path: &std::path::Path,
) -> anyhow::Result<LogMsg> {
let entity_path = re_log_types::EntityPath::from_file_path_as_single_string(file_path);
let cells = re_log_types::data_cells_from_file_path(file_path)?;
let cells = data_cells_from_file_path(file_path)?;

let num_instances = cells.first().map_or(0, |cell| cell.num_instances());

Expand All @@ -97,7 +99,6 @@ fn log_msg_from_file_path(
}

// Non-blocking
#[cfg(not(target_arch = "wasm32"))]
fn stream_rrd_file(
path: std::path::PathBuf,
tx: re_smart_channel::Sender<LogMsg>,
Expand Down
4 changes: 1 addition & 3 deletions crates/re_log_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ serde = [
"re_string_interner/serde",
"re_tuid/serde",
"re_types_core/serde",
"re_types/serde",
]

testing = []

[dependencies]

Expand All @@ -40,7 +40,6 @@ re_string_interner.workspace = true
re_tracing.workspace = true
re_tuid = { workspace = true, features = ["arrow"] }
re_types_core.workspace = true
re_types = { workspace = true, features = ["image"] }

# External
ahash.workspace = true
Expand All @@ -57,7 +56,6 @@ fixed = { version = "1.17", default-features = false, features = ["serde"] }
# `fixed` depends on `half`, so even though `half` is not directly used in this crate,
# we keep it as a direct dependency to ensure it stays pinned on `2.2.1`
half.workspace = true
image.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
num-derive.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/re_log_types/src/data_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl DataCellInner {
fn data_cell_sizes() {
use crate::DataCell;
use arrow2::array::UInt64Array;
use re_types::components::InstanceKey;
use re_types_core::components::InstanceKey;
use re_types_core::Loggable as _;

// not computed
Expand Down
21 changes: 12 additions & 9 deletions crates/re_log_types/src/data_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,15 @@ impl DataTable {

// ---

/// Crafts a simple but interesting [`DataTable`].
#[cfg(not(target_arch = "wasm32"))]
#[cfg(feature = "testing")]
impl DataTable {
/// Crafts a simple but interesting [`DataTable`].
pub fn example(timeless: bool) -> DataTable {
use crate::Time;
use re_types::components::{Color, Position2D, Text};
use crate::{
example_components::{MyColor, MyLabel, MyPoint},
Time,
};

let table_id = TableId::random();

Expand All @@ -1277,9 +1280,9 @@ impl DataTable {

let row0 = {
let num_instances = 2;
let positions: &[Position2D] = &[[10.0, 10.0].into(), [20.0, 20.0].into()];
let colors: &[_] = &[Color::from_rgb(128, 128, 128)];
let labels: &[Text] = &[];
let positions: &[MyPoint] = &[MyPoint::new(10.0, 10.0), MyPoint::new(20.0, 20.0)];
let colors: &[_] = &[MyColor(0x8080_80FF)];
let labels: &[MyLabel] = &[];

DataRow::from_cells3(
RowId::random(),
Expand All @@ -1293,15 +1296,15 @@ impl DataTable {

let row1 = {
let num_instances = 0;
let colors: &[Color] = &[];
let colors: &[MyColor] = &[];

DataRow::from_cells1(RowId::random(), "b", timepoint(1), num_instances, colors).unwrap()
};

let row2 = {
let num_instances = 1;
let colors: &[_] = &[Color::from_rgb(255, 255, 255)];
let labels: &[_] = &[Text("hey".into())];
let colors: &[_] = &[MyColor(0xFFFF_FFFF)];
let labels: &[_] = &[MyLabel("hey".into())];

DataRow::from_cells2(
RowId::random(),
Expand Down
Loading

0 comments on commit 316bddd

Please sign in to comment.