Skip to content

Conversation

pawelmajcher
Copy link

@pawelmajcher pawelmajcher commented Oct 5, 2025

On platforms targeting Swift 6.2 and later this allows a RawSpan in lieu of SwiftProtobufContiguousBytes-conforming type when creating or merging a protobuf message. This will improve memory usage by reducing allocations, for example when parsing a large document that includes protobuf messages as part of its binary. Unlike the internal _merge function, this does not expose unsafe API while retaining its benefits.

  • I decided to make a twin declaration of the initializer and merge function instead of conforming RawSpan to SwiftProtobufContiguousTypes, because
    • a) RawSpan is not mutable, and
    • b) Span types are non-owning and cannot conform to initializers.
  • I used the conditional compilation block and @available directive per analogy to this implementation in SwiftNIO docs.

@FranzBusch FranzBusch added the 🆕 semver/minor Adds new public API. label Oct 6, 2025
@thomasvl thomasvl requested a review from Lukasa October 6, 2025 13:58
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

As an API this makes sense to me, but I'd like to see some tests here.

@pawelmajcher
Copy link
Author

I added test coverage for both initializing and merging messages with RawSpan, but I'm not sure if more extensive testing is needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants