Skip to content
New issue

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

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

Already on GitHub? # to your account

perf: Improve locks in SentryScope #888

Merged
merged 16 commits into from
Jan 11, 2021
Merged

Conversation

philipphofmann
Copy link
Member

@philipphofmann philipphofmann commented Dec 28, 2020

📜 Description

SentryScope contained many locks to self with @synchronized, which are not needed because not the
whole scope is modified in them. Now we only lock the objects, that are modified in the
@synchronized block.

💡 Motivation and Context

Fixes GH-880

💚 How did you test it?

CI.

📝 Checklist

  • I reviewed the submitted code
  • I added tests to verify the changes
  • I updated the CHANGELOG
  • I updated the docs if needed
  • Review from the native team if needed
  • No breaking changes

🔮 Next steps

SentryScope contained many locks to self with @synchronized, which are not needed because not the
whole scope is modified in them. Now we only lock the objects, that are modified in the
@synchronized block.

Fixes GH-880
@philipphofmann philipphofmann added this to the 6.1.0 milestone Dec 28, 2020
@philipphofmann philipphofmann requested a review from a team December 28, 2020 16:14
@philipphofmann philipphofmann self-assigned this Dec 28, 2020
@codecov-io
Copy link

codecov-io commented Dec 28, 2020

Codecov Report

Merging #888 (0594f78) into master (99d92ab) will increase coverage by 0.19%.
The diff coverage is 99.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #888      +/-   ##
==========================================
+ Coverage   94.39%   94.58%   +0.19%     
==========================================
  Files          75       75              
  Lines        3405     3437      +32     
==========================================
+ Hits         3214     3251      +37     
+ Misses        191      186       -5     
Impacted Files Coverage Δ
Sources/Sentry/SentryUser.m 98.30% <97.95%> (+0.43%) ⬆️
Sources/Sentry/SentryScope.m 98.91% <100.00%> (+3.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 99d92ab...0594f78. Read the comment docs.

Sources/Sentry/SentryScope.m Outdated Show resolved Hide resolved
Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

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

Looks much safer now. Great!

I left a few smaller notes.

Would be nice to benchmark a bit with some "real life" size scope and frequency change/clone/serialize just to understand the impact the copies will bring, and we should see some benefits of the fine grained locks.

Also it's great we're one step closer to change the scope notification for a single property and avoid reserializing the whole scope on each change.

Let's hop on a call and discuss this before merging as we chatted before?

Sources/Sentry/SentryScope.m Outdated Show resolved Hide resolved
Tests/SentryTests/SentryScopeSwiftTests.swift Outdated Show resolved Hide resolved
Tests/SentryTests/SentryScopeSwiftTests.swift Outdated Show resolved Hide resolved
Sources/Sentry/SentryScope.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryScope.m Outdated Show resolved Hide resolved
Sources/Sentry/SentryScope.m Show resolved Hide resolved
Sources/Sentry/SentryScope.m Show resolved Hide resolved
Sources/Sentry/SentryScope.m Outdated Show resolved Hide resolved
@philipphofmann philipphofmann merged commit a81025d into master Jan 11, 2021
@philipphofmann philipphofmann deleted the perf/improve-scope-locks branch January 11, 2021 09:03
@philipphofmann philipphofmann mentioned this pull request Mar 17, 2023
7 tasks
philipphofmann added a commit that referenced this pull request Mar 17, 2023
Remove added not needed locks with #888
in SentryUser. The copy, isEqual, serialize, and hash methods don't need to be thread
safe. When modifying the user from multiple threads and calling any of these methods,
the callee should use locks.
philipphofmann added a commit that referenced this pull request Mar 20, 2023
Remove added not needed locks with #888
in SentryUser. The copy, isEqual, serialize, and hash methods don't need to be thread
safe. When modifying the user from multiple threads and calling any of these methods,
the callee should use locks.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve thread safety for SentryScope
3 participants