You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "John Dickson (Jira)" <ji...@apache.org> on 2025/06/27 20:27:00 UTC
[jira] [Created] (AVRO-4160) Replace std::any with std::optional and std::variant in generated structs.
John Dickson created AVRO-4160:
----------------------------------
Summary: Replace std::any with std::optional and std::variant in generated structs.
Key: AVRO-4160
URL: https://issues.apache.org/jira/browse/AVRO-4160
Project: Apache Avro
Issue Type: Improvement
Components: c++
Reporter: John Dickson
C++'s std::any is very powerful, and expensive to use. Since all the types are known, avrogencpp generated structures can leverage std::variant for union types instead. The interface of std::variant maps to the avro union interface, providing a built in union discriminator which removes the need for avro union structures to store a second member variable. More importantly, this relieves a lot of pressure on the memory allocator for deeply nested schemas when unions are heavily used.
In addition, when a union contains two types, and one of those types is null, std::optional can be used for even lighter weight union implementation.
This can be done with no changes to the API. The emitted structures can even be used with previous versions of the avro library.
Real world testing in our case, this single change reduced transaction times by 50%
--
This message was sent by Atlassian Jira
(v8.20.10#820010)