Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol Buffers vs Flat Buffers [closed]

So, I'm currently working on a project where Protocol Buffers is used extensively, mainly as a way to store complex objects in a key-value database.

Would a migration to Flat Buffers provide a considerable benefit in terms of performance?

More in general, is there ever a good reason to use Protocol Buffers instead of Flat Buffers?

like image 527
Matteo Ugolotti Avatar asked Dec 05 '22 15:12

Matteo Ugolotti


2 Answers

Protocol buffers are optimized for space consumption on the wire, so for archival and storage, they are very efficient. However, the complex encoding is expensive to parse, and so they are computationally expensive, and the C++ API makes heavy use of dynamic allocations. Flat buffers, on the other hand, are optimized for efficient parsing and in-memory representation (e.g. offering zero-copy views of the data in some cases).

It depends on your use case which of those aspects is more important to you.

like image 100
Kerrek SB Avatar answered Jan 03 '23 02:01

Kerrek SB


Quoting from the flatbuffer page:

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.

like image 36
Shivendra Agarwal Avatar answered Jan 03 '23 01:01

Shivendra Agarwal