Skip to content

perf: add support for batched scope access - #2107

Open
jpnurmi wants to merge 1 commit into
jpnurmi/ref/scope-flush-funcfrom
jpnurmi/perf/scope-batch-update
Open

jpnurmi wants to merge 1 commit into
jpnurmi/ref/scope-flush-funcfrom
jpnurmi/perf/scope-batch-update

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Keep the scope read or write lock across a batch while allowing the owning thread to use existing scope accessors without relocking.

This tackles two use-cases:

  • Atomic reads of multiple scope properties: don't allow writes from other threads to intervene to ensure consistent data
  • Batched writes of multiple scope properties: one backend flush at the end can result in huge wins in terms of performance

@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 5593400 to a3ffce7 Compare September 17, 2026 14:08
@jpnurmi
jpnurmi added this pull request to stack #2092 September 17, 2026 14:08

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

Stale Bugbot comment from a previous run.

Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from a3ffce7 to a38d913 Compare September 17, 2026 14:18
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from a38d913 to 41100bf Compare September 17, 2026 15:37
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.05970% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.57%. Comparing base (c77cb6e) to head (bf866ff).

Additional details and impacted files
@@                       Coverage Diff                        @@
##           jpnurmi/ref/scope-flush-func    #2107      +/-   ##
================================================================
+ Coverage                         75.55%   75.57%   +0.01%     
================================================================
  Files                               103      103              
  Lines                             28171    28292     +121     
  Branches                           5159     5179      +20     
================================================================
+ Hits                              21286    21383      +97     
- Misses                             5530     5560      +30     
+ Partials                           1355     1349       -6     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpnurmi jpnurmi changed the title perf: add support for batched scope updates perf: add support for batched scope access Sep 18, 2026

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0083711. Configure here.

Comment thread src/sentry_scope.c
Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 0083711 to 3852ecb Compare September 18, 2026 14:48
Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 3852ecb to cef816a Compare September 19, 2026 18:53
Base automatically changed from jpnurmi/perf/global-scope-mutex to master September 20, 2026 06:28
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from aeed6d1 to 2c04bee Compare September 20, 2026 06:28
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 2c04bee to 6dbd749 Compare September 24, 2026 11:06
Comment thread src/sentry_scope.c
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from b81d020 to f97158f Compare September 30, 2026 12:17
@jpnurmi

jpnurmi commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

@limbonaut @tustanivsky some potential candidates for write-locked batch updates that would fold several flushes into one:

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

Looks really neat! 🚢 🗺️
Q: Can users use these with the global scope? Probably need either sentry_begin_write or an actual accesor for the global scope.

@jpnurmi

jpnurmi commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Q: Can users use these with the global scope? Probably need either sentry_begin_write or an actual accesor for the global scope.

Which would you prefer? With sentry_begin_write we'd get away without exposing the global scope and dealing with the consequences just yet, but a global sentry_begin_write reads somewhat awkwardly compared to sentry_scope_begin_write... 🤔

@limbonaut

Copy link
Copy Markdown
Collaborator

It can also be a more explicit name such as sentry_global_scope_begin_write.
I'm not sure what kind of traps we are facing when it comes to exposing an actual accessor.

@jpnurmi

jpnurmi commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

I'm not sure what kind of traps we are facing when it comes to exposing an actual accessor.

Hmmm, now that I think of it, we might have coincidentally eliminated the blocker problems with the recent RW-lock changes.

Before, all global scope access was exclusively locked during SENTRY_WITH_SCOPE macro blocks, and accessing the global scope anywhere outside of those blocks would not have been safe. Now, with RW-locks, any global or local scope instance protects its own data, so it's basically safe to access them anywhere as long as the instance itself is safely ref-counted.

Exposing the global scope is tempting because it would allow being more selective with the global vs. scope API duplication going forward... 🤔

@limbonaut

limbonaut commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Now, with RW-locks, any global or local scope instance protects its own data, so it's basically safe to access them anywhere as long as the instance itself is safely ref-counted.

I think you are right. Something like sentry_get_scope() could be a good name. Eventually, we may want to support isolation scopes, and these API calls would automatically work with such too.

@jpnurmi
jpnurmi marked this pull request as draft October 2, 2026 09:07
@jpnurmi
jpnurmi removed this pull request from stack #2092 October 2, 2026 16:43
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from f97158f to ecb41a7 Compare October 2, 2026 16:55
@jpnurmi
jpnurmi changed the base branch from master to jpnurmi/feat/scope-access October 2, 2026 16:56
@jpnurmi
jpnurmi added this pull request to stack #2161 October 2, 2026 16:56
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch 2 times, most recently from f65ce04 to b1503ad Compare October 3, 2026 07:52
@jpnurmi
jpnurmi marked this pull request as ready for review October 3, 2026 07:53
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from b1503ad to 9646003 Compare October 6, 2026 15:06
@jpnurmi
jpnurmi removed this pull request from stack #2161 October 6, 2026 15:08
@jpnurmi
jpnurmi changed the base branch from jpnurmi/feat/scope-access to jpnurmi/ref/scope-flush-func October 6, 2026 15:08
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch 2 times, most recently from a0d9e0e to 72e1895 Compare October 9, 2026 08:19
@jpnurmi
jpnurmi added this pull request to stack #2183 October 9, 2026 08:28
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 72e1895 to 7eeb226 Compare October 9, 2026 08:40
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 7eeb226 to 441401f Compare October 9, 2026 09:08
Keep the scope write lock across a batch while allowing the owning thread
to use existing scope accessors without relocking. Defer backend scope
flushes until the outermost batch completes.
@jpnurmi
jpnurmi force-pushed the jpnurmi/perf/scope-batch-update branch from 441401f to bf866ff Compare October 9, 2026 10:34
Comment thread src/sentry_scope.c

This branch has not been deployed

No deployments
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