sentry-java icon indicating copy to clipboard operation
sentry-java copied to clipboard

Lazy uuid generation for SentryId and SpanId

Open lbloder opened this issue 1 year ago • 4 comments

:scroll: Description

Use LazyEvaluator to generate UUID on demand in

  • SpanId
  • SentryId

:bulb: Motivation and Context

Fixes #3325

:green_heart: How did you test it?

:pencil: Checklist

  • [ ] I reviewed the submitted code.
  • [ ] 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.
  • [ ] 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.

:crystal_ball: Next steps

lbloder avatar Oct 07 '24 08:10 lbloder

Messages
:book: Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by :no_entry_sign: dangerJS against 58a00c4330c44cd0e8398306a32ea3e3956f3668

github-actions[bot] avatar Oct 07 '24 08:10 github-actions[bot]

Hey @lbloder, I was wondering on how did you test this part? It's not included in the PR.

Angelodaniel avatar Oct 07 '24 14:10 Angelodaniel

@Angelodaniel do you expect problems somewhere? If so, what areas?

adinauer avatar Oct 09 '24 10:10 adinauer

Performance metrics :rocket:

  Plain With Sentry Diff
Startup time 392.57 ms 447.13 ms 54.56 ms
Size 1.70 MiB 2.36 MiB 670.62 KiB

Previous results on branch: feat/lazy-span-id-v8

Startup times

Revision Plain With Sentry Diff
081906a9c55ce90a31a75aed09e67d21098ce649 544.44 ms 604.34 ms 59.90 ms
e2e56a083895b9f077e8c35b9da2a579d03c7272 417.82 ms 484.86 ms 67.04 ms
234085b5b7641b7fcda1c1b607014ccd18cb18dd 560.06 ms 587.22 ms 27.16 ms
2601edf68cbbb8a38f5acc12e172b1b51df5aff3 472.73 ms 518.83 ms 46.10 ms
ab1b958255cb1baccef9d29246e89ce9080178d1 427.50 ms 489.06 ms 61.56 ms
5132e04651b48c1ef6f3d698b05f5bef7a7693ed 431.47 ms 443.96 ms 12.49 ms

App size

Revision Plain With Sentry Diff
081906a9c55ce90a31a75aed09e67d21098ce649 1.70 MiB 2.35 MiB 665.19 KiB
e2e56a083895b9f077e8c35b9da2a579d03c7272 1.70 MiB 2.36 MiB 670.59 KiB
234085b5b7641b7fcda1c1b607014ccd18cb18dd 1.70 MiB 2.36 MiB 670.52 KiB
2601edf68cbbb8a38f5acc12e172b1b51df5aff3 1.70 MiB 2.35 MiB 669.02 KiB
ab1b958255cb1baccef9d29246e89ce9080178d1 1.70 MiB 2.36 MiB 670.54 KiB
5132e04651b48c1ef6f3d698b05f5bef7a7693ed 1.70 MiB 2.36 MiB 670.58 KiB

github-actions[bot] avatar Oct 09 '24 10:10 github-actions[bot]

@stefanosiano I did some tests regarding performance of this change and found another issue, that i fixed in a new commit, if you could take another look that would be great. The SentryFrameMetricsCollector caused lots of unnecessary toString calls to SpanId and thus triggered the UUID generation.

It does not change much in terms of startup time (as reported by Sentry) on a Motorola moto e22 low-end device with Android 12.

However, most of the calls that lead to UUID generation is now done on backround Threads:

8.x.x branch:

Test Calls per Thread
Vanilla android-sample {main:toString=16, SentryExecutorServiceThreadFactory-0:serialize=2}
android-sample with 1 TR and 100 Spans {main:toString=420, SentryAsyncConnection-0:serialize=162}

Lazy branch:

Test Calls per Thread
Vanilla android-sample {main:toString=10, SentryExecutorServiceThreadFactory-0:serialize=2}
android-sample with 1 TR and 100 Spans {main:toString=10, SentryAsyncConnection-0:serialize=105, SentryExecutorServiceThreadFactory-0:serialize=2}

lbloder avatar Oct 23 '24 06:10 lbloder

Will this be cheery picked to the current version?

kozaxinan avatar Nov 02 '24 23:11 kozaxinan

@kozaxinan we're working on releasing another beta for v8 and plan to have it GA soonish so we'd rather focus on v8 than backporting to v7 unless this is a blocking problem for someone.

adinauer avatar Nov 11 '24 14:11 adinauer

@kozaxinan we're working on releasing another beta for v8 and plan to have it GA soonish so we'd rather focus on v8 than backporting to v7 unless this is a blocking problem for someone.

I understand the process. But it is not clear when 8 will be available and when the general audience will migrate. Considering the Christmas season is coming, this could be a nice improvement to the 7 version until we get version 8 next year. It is not a blocker but on slow devices it impacts.

kozaxinan avatar Nov 11 '24 17:11 kozaxinan

v8 GA is planned for mid of December and upgrading should be straight forward. We've just released 8.0.0-beta.2 in case you want to give it a try and see for yourself how much effort upgrading is on your app(s).

adinauer avatar Nov 14 '24 04:11 adinauer