Skip to content

perf: Avoid boxing in doubleToBigDecimal timestamp serialization#5551

Merged
runningcode merged 2 commits into
mainfrom
no/reduce-boxing-double-to-bigdecimal
Jun 17, 2026
Merged

perf: Avoid boxing in doubleToBigDecimal timestamp serialization#5551
runningcode merged 2 commits into
mainfrom
no/reduce-boxing-double-to-bigdecimal

Conversation

@runningcode

Copy link
Copy Markdown
Contributor

📜 Description

DateUtils.doubleToBigDecimal took a boxed Double, so callers holding a primitive double timestamp autoboxed on every serialization. This:

  • Changes the parameter to a primitive double.
  • Consolidates four byte-identical private copies of the helper (ProfileChunk, ProfileMeasurementValue, SentrySample, SentrySpan) to route through the single DateUtils.doubleToBigDecimal.

The classes with primitive double timestamp fields (ProfileChunk, ProfileMeasurementValue, SentrySample) no longer box on each serialize. The protocol classes whose timestamps are Double (SentrySpan, SentryTransaction, SentryLogEvent, SentryMetricsEvent) unbox at the call site instead — behavior is identical, since the previous code already unboxed internally via BigDecimal.valueOf (so null handling is unchanged).

Net -16 lines (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, and JsonSerializerTest cases serializes profileChunk / serializes profileMeasurement / serializes profilingTraceData / serializes transaction), confirming byte-identical JSON output.

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

None.

runningcode and others added 2 commits June 16, 2026 18:24
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>
@sentry

sentry Bot commented Jun 16, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 311.06 ms 356.56 ms 45.50 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

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

@runningcode runningcode marked this pull request as ready for review June 16, 2026 16:37
@runningcode runningcode merged commit ba01011 into main Jun 17, 2026
69 checks passed
@runningcode runningcode deleted the no/reduce-boxing-double-to-bigdecimal branch June 17, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants