perf: Avoid boxing in doubleToBigDecimal timestamp serialization#5551
Merged
Conversation
Change DateUtils.doubleToBigDecimal to take a primitive double instead of a boxed Double, and route the four duplicated private copies (ProfileChunk, ProfileMeasurementValue, SentrySample, SentrySpan) through it. Callers that hold a primitive double timestamp no longer autobox on every serialization, and the duplicated helpers are consolidated into one. Behavior is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 295.53 ms | 373.74 ms | 78.21 ms |
| d15471f | 307.28 ms | 381.85 ms | 74.57 ms |
| 4c04bb8 | 350.71 ms | 413.63 ms | 62.92 ms |
| 9e60aca | 316.18 ms | 345.04 ms | 28.86 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| 46b442b | 321.41 ms | 339.30 ms | 17.89 ms |
| b193867 | 331.08 ms | 397.06 ms | 65.98 ms |
| b6702b0 | 395.86 ms | 409.98 ms | 14.12 ms |
| ed33deb | 312.34 ms | 369.71 ms | 57.37 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 4c04bb8 | 0 B | 0 B | 0 B |
| 9e60aca | 0 B | 0 B | 0 B |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| 46b442b | 0 B | 0 B | 0 B |
| b193867 | 1.58 MiB | 2.19 MiB | 620.00 KiB |
| b6702b0 | 1.58 MiB | 2.12 MiB | 551.79 KiB |
| ed33deb | 1.58 MiB | 2.13 MiB | 559.52 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
markushi
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
DateUtils.doubleToBigDecimaltook a boxedDouble, so callers holding a primitivedoubletimestamp autoboxed on every serialization. This:double.ProfileChunk,ProfileMeasurementValue,SentrySample,SentrySpan) to route through the singleDateUtils.doubleToBigDecimal.The classes with primitive
doubletimestamp fields (ProfileChunk,ProfileMeasurementValue,SentrySample) no longer box on each serialize. The protocol classes whose timestamps areDouble(SentrySpan,SentryTransaction,SentryLogEvent,SentryMetricsEvent) unbox at the call site instead — behavior is identical, since the previous code already unboxed internally viaBigDecimal.valueOf(so null handling is unchanged).Net
-16lines (four duplicate helpers removed).💡 Motivation and Context
Follow-up to the "Reduce boxing to improve performance" effort. Spun out of review on #5550 (
SentryNanotimeDate), where this adjacent boxing site was noticed but kept out of that focused PR.💚 How did you test it?
Existing serialization round-trip tests pass unchanged (
SentryTransactionSerializationTest,SentryProfileSerializationTest, andJsonSerializerTestcasesserializes profileChunk/serializes profileMeasurement/serializes profilingTraceData/serializes transaction), confirming byte-identical JSON output.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None.