TLDR
YaFF is an open supply zero-copy wire format for Protobuf from Yandex (Apache 2.0 (at present C++, v0.1.0)). .proto information stay a supply of reality. Solely the bodily reminiscence structure modifications. In Yandex benchmarks, Flat Structure reads sizzling information roughly 3.8 instances sooner than FlatBuffers and inside 1.2 instances sooner than uncooked C++ buildings. 4 layouts (mounted, flat, sparse, and dynamic) commerce learn velocity for schema flexibility. Default is dynamic. YaFF runs on an advert suggestion system and studies 10-20% CPU financial savings at manufacturing scale. Deployment will happen in levels. Carry out a bidirectional Protobuf transformation on the sting and drop it into one sizzling path.
Yandex open sourced YaFF (One more Flat Format) with Apache 2.0. This can be a excessive efficiency C++ serialization library. YaFF offers a zero-copy wire format to the Protobuf ecosystem. The .proto file stays the one supply of reality. This format solely modifications how the information is organized in reminiscence. It focuses on server-side runtimes.
What’s YaFF?
YaFF will not be a substitute for Protobuf. That is another wire format for Protobuf messages. The identical .proto schema generates a proto-like C++ API. Studying doesn’t require a parsing step, so the fields are retrieved straight from the buffer. Even much less performance-sensitive code can parse the wire format again into Protobuf messages. This bidirectional conversion makes module-by-module deployment sensible. Deploy YaFF on one sizzling path and depart the remaining in Protobuf.
Goal downside
Protobuf parsing can devour double-digit percentages of CPU on closely loaded backends. At scale, it maps to 1000’s of bodily cores. A well-liked zero-copy choice is FlatBuffers, additionally from Google. Nevertheless, FlatBuffers will not be a Protobuf drop-in, so it’s essential to keep a separate schema and transformation layer. Semantically incompatible with Protobuf. Migrations imply duplicate schemas, totally different schema growth guidelines, and hand-written subject converters. Many groups conclude that it’s not price the associated fee. YaFF goals to handle that hole: zero-copy reads that protect Protobuf semantics.
How structure works
The structure determines how messages are saved within the buffer. Solely the bodily illustration modifications; the schema and generated interfaces stay unchanged. YaFF ships with 4 layouts. Mounted plain packed structs with out headers and frozen schemas. Flat provides a 2-byte header and helps schema evolution. Sparse corresponds to fields via meta tables and suits into sparse schemas. Dynamic is the default, and also you select flat or sparse at runtime. Use Flat whereas the schema permits, and change to Sparse when evolution breaks flat alignment.
benchmark
Yandex ships a collection of reproducible benchmarks constructed utilizing google/benchmark in launch builds. The numbers under are the median nanoseconds per learn on an AMD EPYC 7713 with Clang 20.1.8. The decrease the velocity, the sooner it’s. For the new hierarchy, the flat structure learn time is 9.79 ns. FlatBuffers requires 37.30 ns and Protobuf requires 219.35 ns. The baseline for uncooked C++ buildings is 8.14 ns. Subsequently, Flat Structure reads about 3.8 instances sooner than FlatBuffers and about 22 instances sooner than Protobuf. It’s inside 1.2 instances the uncooked construction.
Observe: Absolutely the quantity is dependent upon the host CPU and reminiscence. It’s anticipated that the ratio between codecs will likely be maintained throughout the {hardware}.
Compiler aliasing particulars
Each FlatBuffers and YaFF learn fields by reinterpreting uncooked reminiscence because the goal kind. With such puns, TBAA lacks robust sufficient details. Subsequently, LLVM’s alias evaluation reverts to a conservative MayAlias resolution. On this case, the compiler can’t show that it’s protected to reuse repeated accesses. Writing root.intermediate().leaf().a() twice retraces the tree every time. YaFF provides annotations to the generated code that inform the compiler that it’s protected to reuse. YaFF’s generated code annotations typically assist the compiler reuse entry chains so long as the related reminiscence will not be modified between reads. YaFF caches entry chains by itself until you write something to reminiscence between reads.
Good place: Use case
YaFF targets programs that management each producers and shoppers. Suggestion and advert serving backends are best suited. YaFF runs on an advert suggestion system and studies 10-20% CPU financial savings at manufacturing scale, based on Yandex. Reminiscence-mapped indexes are an excellent second alternative. A number can maintain tens of gigabytes of native information. These mmapable indexes survive service restarts with out reparsing. Search indexes, characteristic shops, and feed companies share read-heavy profiles. The deliberate columnar structure targets analytics and ML pipelines with massive repeating fields. YaFF is extra compact than FlatBuffers, which helps with caching habits.
check out the code
The learn path displays Protobuf with out the parse step.
Add YaFF via CMake (find_package) or Conan. Code era runs protobuf_generate() after which yaff_generate(). The generated YaFF varieties reside within the protoyaff:: namespace. Most initiatives solely hyperlink yaff::core and yaff::proto.
useful resource:
Try our GitHub repository and documentation.


