Skip to content

perf: reduce allocations in ConfigureScope callbacks - #5856

Merged
jamescrosswell merged 3 commits into
getsentry:mainfrom
XAN9xXx:perf/configure-scope-state-overload
Nov 3, 2026
Merged

jamescrosswell merged 3 commits into
getsentry:mainfrom
XAN9xXx:perf/configure-scope-state-overload

Conversation

@XAN9xXx

@XAN9xXx XAN9xXx commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Use the ConfigureScope<TArg> overload with static callbacks to reduce allocations in ASP.NET, Blazor WebAssembly, gRPC, MAUI CommunityToolkit MVVM, and global root scope initialization.

Issues

Closes #5219

@jamescrosswell
jamescrosswell self-requested a review November 2, 2026 21:56

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

Thanks for picking this up @XAN9xXx! CI is failing on two tests in GlobalRootScopeIntegrationTests:

  • Register_GlobalModeEnabled_SetsInstallationIdOnRootScope
  • Register_GlobalModeEnabled_DoesNotOverwriteExistingUserId

They check that the non-generic overload was called:

hub.Received(1).ConfigureScope(Arg.Any<Action<Scope>>());

GlobalRootScopeIntegrationTests.cs#L51 and #L82

GlobalRootScopeIntegration now calls ConfigureScope<SentryOptions>, so those assertions need to match the generic overload:

hub.Received(1).ConfigureScope(Arg.Any<Action<Scope, SentryOptions>>(), Arg.Any<SentryOptions>());

Please change the DidNotReceive() assertion at #L27 the same way. It still passes as written, but it's checking an overload that's no longer called, so it no longer tests anything.

To run just these tests locally:

dotnet test test/Sentry.Tests --filter GlobalRootScopeIntegrationTests

@XAN9xXx

XAN9xXx commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

I've applied the suggestions and updated all three assertions. All GlobalRootScopeIntegrationTests pass locally on .NET 10.
Thanks for the review!

@XAN9xXx
XAN9xXx marked this pull request as ready for review November 3, 2026 10:08
@XAN9xXx
XAN9xXx requested a review from ric-oliv as a code owner November 3, 2026 10:08
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 3, 2026
@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.88889% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.67%. Comparing base (193656c) to head (f264903).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...rc/Sentry.AspNetCore.Grpc/SentryGrpcInterceptor.cs 16.66% 10 Missing ⚠️
...olkit.Mvvm/MauiCommunityToolkitMvvmEventsBinder.cs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5856      +/-   ##
==========================================
- Coverage   76.69%   76.67%   -0.02%     
==========================================
  Files         528      528              
  Lines       19527    19524       -3     
  Branches     3840     3840              
==========================================
- Hits        14976    14971       -5     
- Misses       3667     3668       +1     
- Partials      884      885       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Nice - thanks @XAN9xXx ❤️

@jamescrosswell
jamescrosswell merged commit 2b324b1 into getsentry:main Nov 3, 2026
57 checks passed
@XAN9xXx
XAN9xXx deleted the perf/configure-scope-state-overload branch November 4, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: use ConfigureScope overload to avoid Closure allocations where possible

2 participants