协议缓冲区与平面缓冲区

Protocol Buffers vs Flat Buffers

所以,我目前正在做一个广泛使用 Protocol Buffers 的项目,主要是作为一种在键值数据库中存储复杂对象的方法。

迁移到 Flat Buffers 会在性能方面提供相当大的好处吗?

更一般地说,是否有充分的理由使用 Protocol Buffers 而不是 Flat Buffers?

协议缓冲区针对 space 在线消耗进行了优化,因此对于存档和存储而言,它们非常高效。然而,复杂的编码解析起来很昂贵,因此它们在计算上也很昂贵,而且 C++ API 大量使用动态分配。另一方面,平面缓冲区针对高效解析和内存中表示进行了优化(例如,在某些情况下提供数据的零拷贝视图)。

这取决于您的用例,哪些方面对您更重要。

引自 flatbuffer 页面:

Why not use Protocol Buffers, or .. ?

Protocol Buffers is indeed relatively similar to FlatBuffers, with the primary difference being that FlatBuffers does not need a parsing/ unpacking step to a secondary representation before you can access data, often coupled with per-object memory allocation. The code is an order of magnitude bigger, too. Protocol Buffers has neither optional text import/export nor schema language features like unions.