ref(core): Avoid boxing in DateUtils.nanosToDate#5523
Open
runningcode wants to merge 2 commits into
Open
Conversation
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>
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| 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 |
0xadam-brown
approved these changes
Jun 10, 2026
|
|
||
| - 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)) |
Member
There was a problem hiding this comment.
super nit: Could just add the PR reference here to the line above, as this is a quick fix. Up to you of course.
Contributor
Author
There was a problem hiding this comment.
Actually I think we just made a release so I'll need to rebase this PR.
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
Implementing @0xadam-brown 's suggestion here: https://github.com/getsentry/sentry-java/pull/5520/changes#r3387804225
DateUtils.nanosToDatestored the result ofnanosToMillis(...)— which already returns a primitivedouble— in a boxedDouble, then unboxed it again viamillis.longValue(). This change keeps the value primitive and replaces the unbox with a plain(long)cast.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
None.