Skip to content

Convert dispatch queue wrapper#5459

Closed
noahsmartin wants to merge 2 commits into
mainfrom
convertDispatchQueueWrapperSwift
Closed

Convert dispatch queue wrapper#5459
noahsmartin wants to merge 2 commits into
mainfrom
convertDispatchQueueWrapperSwift

Conversation

@noahsmartin

@noahsmartin noahsmartin commented Jun 22, 2025

Copy link
Copy Markdown
Contributor

📜 Description

Convert SentryDispatchQueueWrapper to Swift

dispatch_once doesn't have a Swift equivalent but the wrapper was only used in one place, so I just converted that to be used directly with a check for if tests are trying to override it with a stub.

Also the legacy queue priority is not replaced with QoS in Swift. I created new initializers for utility and userInitiated, which are the only QoS that was being used from the objc queue attributes.

#skip-changelog

💚 How did you test it?

Updated existing tests

📝 Checklist

You have to check all boxes before merging:

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

@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch from 5c845bd to 64cea2a Compare June 22, 2025 19:31
@codecov

codecov Bot commented Jun 22, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 96.74797% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.248%. Comparing base (2b02431) to head (e96866d).
Report is 53 commits behind head on main.

Files with missing lines Patch % Lines
...Swift/Core/Helper/SentryDispatchQueueWrapper.swift 95.402% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #5459       +/-   ##
=============================================
+ Coverage   86.238%   86.248%   +0.010%     
=============================================
  Files          399       399               
  Lines        34814     34818        +4     
  Branches     15097     15098        +1     
=============================================
+ Hits         30023     30030        +7     
  Misses        4744      4744               
+ Partials        47        44        -3     
Files with missing lines Coverage Δ
SentryTestUtils/TestDispatchFactory.swift 100.000% <100.000%> (+29.411%) ⬆️
...ntryTestUtils/TestSentryDispatchQueueWrapper.swift 89.830% <100.000%> (ø)
...urces/Sentry/Profiling/SentryContinuousProfiler.mm 91.176% <ø> (ø)
Sources/Sentry/Profiling/SentryLaunchProfiling.m 89.015% <ø> (ø)
...entry/Profiling/SentryProfiledTracerConcurrency.mm 92.760% <ø> (ø)
Sources/Sentry/Profiling/SentryProfilerState.mm 99.328% <ø> (ø)
Sources/Sentry/Profiling/SentryTraceProfiler.mm 95.522% <ø> (ø)
Sources/Sentry/SentryANRTrackerV1.m 99.212% <ø> (ø)
Sources/Sentry/SentryANRTrackerV2.m 98.863% <ø> (ø)
Sources/Sentry/SentryANRTrackingIntegration.m 99.378% <ø> (ø)
... and 32 more

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

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

@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 4 times, most recently from 08bf4a4 to 09a3620 Compare June 22, 2025 20:27
@github-actions

github-actions Bot commented Jun 22, 2025

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1213.21 ms 1238.37 ms 25.16 ms
Size 23.75 KiB 857.50 KiB 833.75 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
2691350 1224.92 ms 1255.82 ms 30.90 ms

App size

Revision Plain With Sentry Diff
2691350 23.75 KiB 850.73 KiB 826.98 KiB

@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 4 times, most recently from 53a4e2c to 0bdf842 Compare June 22, 2025 22:15
@noahsmartin noahsmartin marked this pull request as ready for review June 23, 2025 02:19
@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 2 times, most recently from 73f43a7 to 0cefa2e Compare June 23, 2025 02:54

@philprime philprime left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Found a couple of issues to look into

Comment thread CHANGELOG.md Outdated
Comment thread Sources/Sentry/SentryCrashIntegration.m
Comment thread Tests/SentryTests/Networking/SentryDispatchFactoryTests.m Outdated
Comment thread Tests/SentryTests/Networking/SentryDispatchFactoryTests.m Outdated
Comment thread Tests/SentryTests/Networking/SentryDispatchFactoryTests.m
Comment thread Tests/SentryTests/Networking/SentryDispatchQueueWrapperTests.m
Comment thread Sources/Swift/Core/Helper/SentryDispatchQueueWrapper.swift Outdated
Comment thread Sources/Sentry/SentryTransportFactory.m Outdated
@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 2 times, most recently from 60f4843 to 36a8c7f Compare June 23, 2025 15:23
@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 6 times, most recently from 6d76682 to 322dcd3 Compare June 23, 2025 18:28
@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch 4 times, most recently from b676d58 to 0ebd0f2 Compare June 23, 2025 20:56
@noahsmartin noahsmartin force-pushed the convertDispatchQueueWrapperSwift branch from 0ebd0f2 to e96866d Compare June 23, 2025 23:31
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Detected changes in high risk code 🚨

High-risk code can easily blow up and is hard to test. We had severe bugs in the past. Be extra careful when changing these files, and have an extra careful look at these:

  • Sources/Sentry/SentryFileManager.m
  • Sources/Sentry/SentrySubClassFinder.m
  • Sources/Sentry/SentryUIViewControllerSwizzling.m

@philipphofmann philipphofmann left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for trying to convert more code to Swift. Unfortunately, I don't think we can do such a refactoring in one go. The risk is way too high to break things. The SentryDispatchQueueWrapper is heavily used in the SDK, and we don't have enough integration tests to ensure migrating this won't introduce any significant issues. If we mess this up, the whole SDK can be broken.

I would instead choose an opportunistic approach. I would create a duplicate class in Swift for the SentryDispatchQueueWrapper. Whenever we need parts from the SentryDispatchQueueWrapper in Swift, we add it. Once we know it's working correctly, we can let ObjC code use the new Swift class step by step. It might be OK, to keep a SentryDispatchQueueWrapper for specific parts of the SDK.

Does that make sense, @noahsmartin?

@philipphofmann

Copy link
Copy Markdown
Member

#5472 replaces this PR due to the concerns pointed out in #5459 (review). That's why we closed it.

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.

3 participants