Skip to content

fix(perfetto): Introduces memory/size limits for perfetto conversion#6244

Open
Dav1dde wants to merge 1 commit into
dav1d/improve-perfettofrom
dav1d/memory-limits
Open

fix(perfetto): Introduces memory/size limits for perfetto conversion#6244
Dav1dde wants to merge 1 commit into
dav1d/improve-perfettofrom
dav1d/memory-limits

Conversation

@Dav1dde

@Dav1dde Dav1dde commented Jul 17, 2026

Copy link
Copy Markdown
Member

Fixes: INGEST-1017

@Dav1dde
Dav1dde requested a review from a team as a code owner July 17, 2026 10:56
@linear-code

linear-code Bot commented Jul 17, 2026

Copy link
Copy Markdown

INGEST-1017

@Dav1dde Dav1dde self-assigned this Jul 17, 2026
cursor[bot]

This comment was marked as low quality.

Comment thread relay-profiling/src/perfetto/convert/cache.rs
Comment thread relay-profiling/src/perfetto/convert/intern.rs
@Dav1dde
Dav1dde requested a review from markushi July 17, 2026 11:46
/// Returns [`BudgetExceeded`] if the memory budget is exhausted.
pub fn insert(&mut self, k: K, v: V) -> Result<Option<V>, BudgetExceeded> {
let key_size = k.size();
self.budget.try_add(key_size + v.size())?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can fail even though you theoretically have enough budget, because you're temporarily consuming the key's size twice. Probably doesn't matter much in practice.

Comment on lines +228 to +239
macro_rules! impl_budget_size_vec_copy {
($T:ty) => {
impl BudgetSize for Vec<$T>
where
$T: Copy,
{
fn size(&self) -> usize {
std::mem::size_of::<Vec<$T>>() + (self.len() * std::mem::size_of::<$T>())
}
}
};
}

@loewenheim loewenheim Jul 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't this more generally be impl<T> BudgetSize for Vec<T> where T: BudgetSize (using T's size method instead of size_of, of course)? I think the logic should always be the same—the memory consumption of the Vec is the memory consumption of all items plus the overhead of the Vec itself.

let cache = self.cache.entry(seq_id).or_default();
// Technically this is off by-one, but significantly easier to handle.
if self.inner.len() >= consts::MAX_SEQUENCE_IDS {
return Err(BudgetExceeded);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sounds legit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants