Skip to content

perf(profiling): Read Perfetto trace straight into the envelope payload - #6743

Merged
romtsn merged 4 commits into
mainfrom
perf/perfetto-chunk-single-allocation
Nov 25, 2026
Merged

romtsn merged 4 commits into
mainfrom
perf/perfetto-chunk-single-allocation

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

SentryEnvelopeItem.fromPerfettoProfileChunk used to build the payload in three steps. readBytesFromFile streamed the trace into a growing ByteArrayOutputStream, toByteArray() copied that, and then the result was copied a third time into a new [metadata][trace] array. A trace can be up to 50 MB, so at peak the trace could be in memory about three times, which is a real OOM risk on low-end devices.

Now the payload array is sized once (metadata length plus file length), and the trace file is read directly into its slot after the metadata. The checks stay the same: the file must be readable and no larger than MAX_PROFILE_CHUNK_SIZE, and it's deleted whether the read succeeds or fails. If the file shrinks or grows between the size check and the read, the read fails instead of sending a truncated trace.

The new helper is private to SentryEnvelopeItem, so the public API doesn't change. The other profile paths still use readBytesFromFile.

via roman.

--

View Session [Sentry]

sentry-junior Bot and others added 2 commits November 23, 2026 18:18
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit cfefc5a.

Main concerns: reach, host stability.

This label is a hint for reviewers, not an approval.

@sentry

sentry Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.65.1 (1) release

⚙️ sentry-android Build Distribution Settings

…ingle-allocation

# Conflicts:
#	CHANGELOG.md
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@romtsn
romtsn marked this pull request as ready for review November 23, 2026 18:32
@romtsn
romtsn requested review from a team and adinauer as code owners November 23, 2026 18:32
@romtsn
romtsn requested review from 0xadam-brown and romtsn and removed request for a team November 23, 2026 18:32
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 23, 2026
@romtsn romtsn added the sanity-check PR needs a lightweight review for obvious issues label Nov 23, 2026
…ingle-allocation

# Conflicts:
#	CHANGELOG.md
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Nov 25, 2026
@romtsn
romtsn merged commit 9a7574b into main Nov 25, 2026
50 checks passed
@romtsn
romtsn deleted the perf/perfetto-chunk-single-allocation branch November 25, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium sanity-check PR needs a lightweight review for obvious issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants