Skip to content

SwiftQUIC: Change LogPrefixer from a class to a struct - #215

Open
agnosticdev wants to merge 2 commits into
mainfrom
agnosticdev/Logprefixer
Open

agnosticdev wants to merge 2 commits into
mainfrom
agnosticdev/Logprefixer

Conversation

@agnosticdev

Copy link
Copy Markdown
Collaborator

This change moves LogPrefixer from a class to a struct.
Result is fewer allocations and less ARC traffic as its moved around the stack.

@agnosticdev
agnosticdev requested a review from rnro October 4, 2026 19:41
@agnosticdev agnosticdev added the 🔨 semver/patch No public API change. label Oct 4, 2026
@agnosticdev
agnosticdev requested a review from tfpauly as a code owner October 4, 2026 19:41
@rpaulo

rpaulo commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

How does this change the memory allocation?

@agnosticdev

Copy link
Copy Markdown
Collaborator Author

How does this change the memory allocation?

LogPrefixer is a class so it gets saved on the heap when used, changing to a struct avoids that. Also, because it’s a class when it’s passed around we previously incurred a swift_retain. This also avoids that.

@agnosticdev

Copy link
Copy Markdown
Collaborator Author

Regarding #204, this change now makes any copies of the congestion control algorithm that need to be made a lot less CPU intensive. For example on the hot path with this change in QUICPath.congestionControlPacketsAcked(bytesAcked:sentTime:) I see:

8.88 M 0.4%	8.88 M	  outlined enum tag store of CongestionControl	
7.28 M 0.4%	7.28 M	  outlined enum get tag of CongestionControl	

When it used to be:

19.79 M	outlined enum tag store of CongestionControl	
13.13 M outlined enum get tag of CongestionControl	

@rpaulo

rpaulo commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

LogPrefixer is a class so it gets saved on the heap when used, changing to a struct avoids that. Also, because it’s a class when it’s passed around we previously incurred a swift_retain. This also avoids that.

I was asking how much more memory will this use because now we are copying it around and before we took a reference.

@rpaulo

rpaulo commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

I have tried to make this change before and quickly realized that this wouldn't work: the real log prefix is set after the connection starts and after many of the LogPrefixer instances are created. Since they all reference the same LogPrefixer object, they will all get the correct "[C]" after the connection starts. As is, this PR will break logging.

@rpaulo rpaulo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this breaks logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants