Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy uuid generation for SentryId and SpanId #3770

Merged
merged 18 commits into from
Oct 29, 2024
Merged

Conversation

lbloder
Copy link
Collaborator

@lbloder lbloder commented Oct 7, 2024

📜 Description

Use LazyEvaluator to generate UUID on demand in

  • SpanId
  • SentryId

💡 Motivation and Context

Fixes #3325

💚 How did you test it?

📝 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.

🔮 Next steps

Copy link
Contributor

github-actions bot commented Oct 7, 2024

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

Generated by 🚫 dangerJS against 58a00c4

@lbloder lbloder marked this pull request as ready for review October 7, 2024 11:59
@Angelodaniel
Copy link
Member

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

@adinauer
Copy link
Member

adinauer commented Oct 9, 2024

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

Copy link
Contributor

github-actions bot commented Oct 9, 2024

Performance metrics 🚀

  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
081906a 544.44 ms 604.34 ms 59.90 ms
e2e56a0 417.82 ms 484.86 ms 67.04 ms
234085b 560.06 ms 587.22 ms 27.16 ms
2601edf 472.73 ms 518.83 ms 46.10 ms
ab1b958 427.50 ms 489.06 ms 61.56 ms
5132e04 431.47 ms 443.96 ms 12.49 ms

App size

Revision Plain With Sentry Diff
081906a 1.70 MiB 2.35 MiB 665.19 KiB
e2e56a0 1.70 MiB 2.36 MiB 670.59 KiB
234085b 1.70 MiB 2.36 MiB 670.52 KiB
2601edf 1.70 MiB 2.35 MiB 669.02 KiB
ab1b958 1.70 MiB 2.36 MiB 670.54 KiB
5132e04 1.70 MiB 2.36 MiB 670.58 KiB

}

@Override
public String toString() {
return StringUtils.normalizeUUID(uuid.toString()).replace("-", "");
return StringUtils.normalizeUUID(lazyValue.getValue().toString()).replace("-", "");

Choose a reason for hiding this comment

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

This toString is called from multiple places. since uuid wont be changes. it is good to cache that. but also this toString will do unnecessary calculations.
Please consider holding toString value instead of uuid similar to SpanId or also cache the toString result.

Choose a reason for hiding this comment

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

It is more related to #3772
But if toString is called right after creating SentryId, it wont help much of delaying this UUID cost.

Copy link
Member

Choose a reason for hiding this comment

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

@adinauer -> Please see comment from @kozaxinan

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we should measure impact of this PR. I'm afraid this doesn't have the desired effect due to toString(), hashCode and equals being called early. Caching the value for toString() might have a bigger impact, thanks for the suggestion.
Changing how we use IDs (i.e. only generate them when sending) will be a bigger change and I'm not entirely certain it's possible. Offering a configurable ID generation mechanism might be the better approach. We'll discuss internally and update once we know more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kozaxinan Good point, I'll rework SentryId to cache the resulting String instead of the UUID object.

As mentioned by @adinauer, measuring the performance impact of this change has yet to be done.

Choose a reason for hiding this comment

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

Nice this will allow more improvement. Will this be ported to version 7?

Copy link
Member

Choose a reason for hiding this comment

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

@kozaxinan we're planning to explore multiple options to improve the SDK. We can check which of those make sense to port to v7 when we know which ones we'll keep.

@lbloder lbloder mentioned this pull request Oct 21, 2024
Copy link
Member

@stefanosiano stefanosiano left a comment

Choose a reason for hiding this comment

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

just some cleanup, but looks good!
do we already know the impact of this change?

sentry/src/main/java/io/sentry/protocol/SentryId.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/protocol/SentryId.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/protocol/SentryId.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/protocol/SentryId.java Outdated Show resolved Hide resolved
sentry/src/main/java/io/sentry/protocol/SentryId.java Outdated Show resolved Hide resolved
@lbloder
Copy link
Collaborator Author

lbloder commented Oct 23, 2024

@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 lbloder merged commit d2c4d5e into 8.x.x Oct 29, 2024
22 checks passed
@lbloder lbloder deleted the feat/lazy-span-id-v8 branch October 29, 2024 14:58
@kozaxinan
Copy link

Will this be cheery picked to the current version?

@adinauer
Copy link
Member

@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.

@kozaxinan
Copy link

@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.

@adinauer
Copy link
Member

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).

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.

6 participants