SwiftQUIC: PERF: Reduce exclusive access checks by 1.1 gigacycles in the send path - #114
Open
agnosticdev wants to merge 6 commits into
Open
SwiftQUIC: PERF: Reduce exclusive access checks by 1.1 gigacycles in the send path#114agnosticdev wants to merge 6 commits into
agnosticdev wants to merge 6 commits into
Conversation
rpaulo
reviewed
Aug 24, 2026
| path.pathStatistics[.txPackets] += 1 | ||
| path.pathStatistics[.txBytes] += Int(totalPacketLength) | ||
| } | ||
| path.pathStatistics[.txPackets] += 1 |
Contributor
There was a problem hiding this comment.
Why don't path statistics work the same way as connection statistics? path.stats.increment(.txPackets)
Collaborator
Author
There was a problem hiding this comment.
I think I forgot to change path stats when I initially overhauled this (before this pr). Overhauled them in connection. Addressed 9ba1c9f
tfpauly
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swift has something called exclusive access checks, its part of what makes Swift a memory safe language. These exclusive access checks happen when accessing properties of a class or other reference type to make sure something else is not accessing and mutating that property at the same time. These exclusive access checks end up costing a very small amount of CPU when a property of a reference type is used. Well, in the data path (millions of times) these very small amounts of CPU add up to becoming a lot of CPU. One thing you can do to avoid these costs and still keep your code safe is to hoist these properties up to the top of the call stack and pass them down through the stack. This ends up satisfying the ownership rules and avoids redundant exclusive access checks. And that's what this change does, it rewrites the send path to reduce calling
QUICConnectionproperties directly on the send path, and instead, passes these properties down through the send path. This change reduces the CPU usage by over 1.1 gigacycles.Top of tree:
With this change: