Skip to content

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Oct 9, 2025

📜 Description

Avoid forking rootScopes for Reactor if current thread has NoOpScopes.

SentryReactorThreadLocalAccessor.getValue() invokes Sentry.getCurrentScopes() which will fork rootScopes if there is no instance of IScopes available (null or NoOpScopes).

We now check for existence of IScopes before invoking getCurrentScopes() in order to avoid the unnecessary overhead.

💡 Motivation and Context

Potential fix for #4762

💚 How did you test it?

📝 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

cursor[bot]

This comment was marked as outdated.

}

@ApiStatus.Internal
public static boolean hasScopes() {
Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative to exposing this could be to have an overload of Sentry.getCurrentScopes() that could e.g. have a bool parameter to specify whether to fork rootScopes or just return NoOpScopes if there's nothing there yet.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah I would prefer this option, however for the purpose of the release I'm fine to go with this for now

@github-actions
Copy link
Contributor

github-actions bot commented Oct 9, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 309.91 ms 355.42 ms 45.50 ms
Size 1.58 MiB 2.13 MiB 557.34 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
7314dbe 437.83 ms 505.64 ms 67.81 ms
dcc6bbf 382.58 ms 462.13 ms 79.54 ms
a5ab36f 316.83 ms 394.54 ms 77.71 ms
27d7cf8 314.17 ms 347.00 ms 32.83 ms
96449e8 361.30 ms 423.39 ms 62.09 ms
ee747ae 554.98 ms 611.50 ms 56.52 ms
d217708 409.83 ms 474.72 ms 64.89 ms
fcec2f2 311.35 ms 384.94 ms 73.59 ms
85d7417 347.21 ms 394.35 ms 47.15 ms
bdbe1f4 380.66 ms 464.44 ms 83.78 ms

App size

Revision Plain With Sentry Diff
7314dbe 1.58 MiB 2.10 MiB 533.45 KiB
dcc6bbf 1.58 MiB 2.12 MiB 553.10 KiB
a5ab36f 1.58 MiB 2.12 MiB 555.26 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
96449e8 1.58 MiB 2.11 MiB 539.35 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.51 KiB
85d7417 1.58 MiB 2.10 MiB 533.44 KiB
bdbe1f4 1.58 MiB 2.11 MiB 538.88 KiB

Previous results on branch: feat/reduce-scope-forking-for-reactor

Startup times

Revision Plain With Sentry Diff
5f2bb4e 313.63 ms 353.94 ms 40.31 ms

App size

Revision Plain With Sentry Diff
5f2bb4e 1.58 MiB 2.12 MiB 555.28 KiB

}

@ApiStatus.Internal
public static boolean hasScopes() {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah I would prefer this option, however for the purpose of the release I'm fine to go with this for now

@adinauer adinauer merged commit d872fbc into main Nov 25, 2025
61 of 62 checks passed
@adinauer adinauer deleted the feat/reduce-scope-forking-for-reactor branch November 25, 2025 14:02
43jay pushed a commit that referenced this pull request Nov 25, 2025
…es (#4793)

* Avoid forking rootScopes for Reactor if current thread has NoOpScopes

* release: 8.23.1-alpha.1

* fix changelog; replace hasScopes with bool param on getCurrentScopes

* move changelog entry

* move changelog again

---------

Co-authored-by: getsentry-bot <bot@sentry.io>
Co-authored-by: getsentry-bot <bot@getsentry.com>
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.

4 participants