Skip to content

profiler: Don't store the unnecessary length field for Sample Observations#219

Merged
danielsn merged 17 commits into
mainfrom
dsn/observation-inside-map
Aug 22, 2023
Merged

profiler: Don't store the unnecessary length field for Sample Observations#219
danielsn merged 17 commits into
mainfrom
dsn/observation-inside-map

Conversation

@danielsn

@danielsn danielsn commented Aug 17, 2023

Copy link
Copy Markdown
Contributor

What does this PR do?

Replaces the 24 byte Vec<i64> used by each sample with an 8 byte pointer.

Motivation

Each sample has a vec of observations, which has both a capacity and a length member, both of which are 8 bytes. This is wasteful, because all observations for a Profile are of the same length. Instead, we only actually need a single pointer, and can store the length off to the side.

Additional Notes

  • This has unsafe code and could use an extra careful review.
  • I realized that the correct abstraction layer for storing the length field is the Map. All we do is put stuff into the map, and then iterate over it later. This means that each map carries its own ObservationLength along with it, allowing multiple profiles to coexist happily.

How to test the change?

I added a bunch of tests. You can check them for functional correctness using

cargo test profile::internal::observation

You can also check them for memory leaks and UB using miri:

cargo +nightly miri test profile::internal::observation

Note that doing so may require you to cargo update first to avoid issues with an old version of proc_macros interacting badly with miri

@github-actions github-actions Bot added the profiling Relates to the profiling* modules. label Aug 17, 2023
@danielsn
danielsn force-pushed the dsn/observation-inside-map branch from a7287a9 to 94919c5 Compare August 18, 2023 14:28
@danielsn
danielsn force-pushed the dsn/observation-inside-map branch from 2f6bd1b to 996c18e Compare August 18, 2023 18:43
@danielsn
danielsn marked this pull request as ready for review August 18, 2023 18:43
@danielsn
danielsn requested a review from a team as a code owner August 18, 2023 18:43
@danielsn
danielsn force-pushed the dsn/observation-inside-map branch from 8dfab97 to 6703b47 Compare August 21, 2023 19:46
Comment thread profiling/src/profile/mod.rs
morrisonlevi
morrisonlevi previously approved these changes Aug 21, 2023
Odd that locally my clippy did not whine
@morrisonlevi
morrisonlevi force-pushed the dsn/observation-inside-map branch from 9d52cd1 to 6fa9625 Compare August 21, 2023 23:23
@danielsn
danielsn merged commit bb8731a into main Aug 22, 2023
@danielsn
danielsn deleted the dsn/observation-inside-map branch August 22, 2023 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

profiling Relates to the profiling* modules.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants