Skip to content

ref(core): Avoid boxing in DateUtils.nanosToDate#5523

Open
runningcode wants to merge 2 commits into
mainfrom
no/ref-avoid-boxing-nanos-to-date
Open

ref(core): Avoid boxing in DateUtils.nanosToDate#5523
runningcode wants to merge 2 commits into
mainfrom
no/ref-avoid-boxing-nanos-to-date

Conversation

@runningcode

@runningcode runningcode commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📜 Description

Implementing @0xadam-brown 's suggestion here: https://github.com/getsentry/sentry-java/pull/5520/changes#r3387804225

DateUtils.nanosToDate stored the result of nanosToMillis(...) — which already returns a primitive double — in a boxed Double, then unboxed it again via millis.longValue(). This change keeps the value primitive and replaces the unbox with a plain (long) cast.

// before
final Double millis = nanosToMillis((double) nanos); // box
return getDateTime(millis.longValue());              // unbox

// after
final double millis = nanosToMillis((double) nanos);
return getDateTime((long) millis);

📝 Checklist

  • I added GH Issue ID & Linear ID
  • 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 10, 2026 14:48
nanosToMillis already returns a primitive double, but the result was
stored in a boxed Double and then unboxed again via longValue(). Keep
the value primitive to drop the redundant allocation and unboxing on
this conversion, which runs whenever a SentryDate is turned into a
java.util.Date.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sentry

sentry Bot commented Jun 10, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

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

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 321.80 ms 346.08 ms 24.29 ms
Size 0 B 0 B 0 B

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
5b66efd 308.67 ms 363.85 ms 55.18 ms
648fbf7 314.87 ms 358.48 ms 43.61 ms
4c04bb8 350.71 ms 413.63 ms 62.92 ms
ee747ae 396.82 ms 441.67 ms 44.86 ms
ad8da22 365.86 ms 427.00 ms 61.14 ms
d15471f 294.13 ms 399.49 ms 105.36 ms
96eeafa 361.43 ms 455.07 ms 93.63 ms
4fc476b 280.63 ms 363.04 ms 82.42 ms
ee747ae 382.73 ms 435.41 ms 52.68 ms
604a261 380.65 ms 451.27 ms 70.62 ms

App size

Revision Plain With Sentry Diff
5b66efd 1.58 MiB 2.13 MiB 559.07 KiB
648fbf7 0 B 0 B 0 B
4c04bb8 0 B 0 B 0 B
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
96eeafa 1.58 MiB 2.19 MiB 620.21 KiB
4fc476b 0 B 0 B 0 B
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
604a261 1.58 MiB 2.10 MiB 533.42 KiB

@runningcode runningcode marked this pull request as ready for review June 10, 2026 13:37
Comment thread CHANGELOG.md

- Improve SDK init performance by replacing `java.net.URI` with custom string parsing for DSN ([#5448](https://github.com/getsentry/sentry-java/pull/5448))
- Remove unnecessary boxing to improve performance ([#5520](https://github.com/getsentry/sentry-java/pull/5520))
- Reduce unboxing in `DateUtils.nanosToDate` ([#5523](https://github.com/getsentry/sentry-java/pull/5523))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

super nit: Could just add the PR reference here to the line above, as this is a quick fix. Up to you of course.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually I think we just made a release so I'll need to rebase this PR.

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