Skip to content

perf(core): [SDK Overhead Reduction 5] Replace Calendar with Date in DateUtils#5589

Open
adinauer wants to merge 2 commits into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-date-utils
Open

perf(core): [SDK Overhead Reduction 5] Replace Calendar with Date in DateUtils#5589
adinauer wants to merge 2 commits into
perf/sdk-overhead-reductionfrom
perf/sdk-overhead-reduction-date-utils

Conversation

@adinauer

@adinauer adinauer commented Jun 22, 2026

Copy link
Copy Markdown
Member

PR Stack (SDK Overhead Reduction)


📜 Description

Replace Calendar.getInstance(TIMEZONE_UTC).getTime() with new Date() in DateUtils.getCurrentDateTime(), and replace the Calendar conversion in DateUtils.getDateTime(long) with new Date(millis).

Date stores epoch milliseconds and has no timezone state, so the returned values are unchanged. The UTC Calendar was only doing unnecessary allocation and calendar field computation before returning the same epoch millis as a Date.

Also update a stale Breadcrumb memoization comment that referenced Calendar allocation.

💡 Motivation and Context

Part of the SDK Overhead Reduction stack. DateUtils is used in hot event, breadcrumb, and session timestamp paths. Constructing Calendar for these helpers is unnecessary because no calendar fields are used. The change keeps Android/JDK compatibility and avoids introducing java.time or desugaring requirements.

💚 How did you test it?

  • ./gradlew :sentry:test --tests io.sentry.DateUtilsTest — all tests pass
  • ./gradlew spotlessApply apiDump — no API surface changes

📝 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

More SDK overhead reduction PRs in this stack.

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

Avoid constructing Calendar instances when DateUtils only needs the current epoch millis or a Date for an existing millis value. Date stores epoch millis without timezone state, so the returned values are unchanged while avoiding unnecessary Calendar allocation and field computation.

Co-Authored-By: Claude <noreply@anthropic.com>
@sentry

sentry Bot commented Jun 22, 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 312.66 ms 364.94 ms 52.28 ms
Size 0 B 0 B 0 B

@lbloder lbloder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@adinauer

Copy link
Copy Markdown
Member Author

Cursor review

@adinauer

Copy link
Copy Markdown
Member Author

@sentry review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d2ebaed. Configure here.

@adinauer adinauer marked this pull request as ready for review June 24, 2026 08:09
Comment thread sentry/src/main/java/io/sentry/DateUtils.java

@runningcode runningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Much simpler and faster! Great

Comment thread sentry/src/main/java/io/sentry/DateUtils.java
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.

3 participants