I’m migrating a project to support protocol buffers to be stored optimally in a database, but I need a way to efficiently use ContiguousArray and Set (+ InlineArray and noncopyables in the future?) types at runtime for doing the business logic as the project heavily relies on performant data structures.
Are the only solutions to my problem manually editing the generated structs or maintaining separate files when I need the runtime performance? I feel like swift-protobuf should optionally support this feature even if an extra step would be required to do so.
It’s somewhat challenging for swift-protobuf to support arbitrary collections in the generated types because it relies on a number of semantic properties of its outputs. However, I absolutely recommend that you essentially redefine types: use the protobuf types as your serialization data types, and then have a different representation for your in-memory computation.
The messages generated by swift-protobuf are solely meant to be a type-safe mechanism to serialize data across the wire. They are not designed to be general purpose model types that can be used by other layers of your business logic, especially if you need something more sophisticated than what is generated today. No other mainstream language's implementation (that I'm aware of) allows arbitrary collection types to be substituted during generation, and Swift should be no different here.
Please don't modify the generated code to achieve this either, because there's a good chance that we will break you in the future. We don't make any guarantees about what the generated code looks like except for the non-private, non-underscore-prefixed APIs that it exposes.