TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

FlatBuffers: a memory efficient serialization library

126 点作者 rw将近 11 年前

6 条评论

onedognight将近 11 年前
Interesting that Cap&#x27;n Proto[1] is not even mentioned given that this library has similar if not the same goals and lineage.<p>[1] <a href="http://kentonv.github.io/capnproto/" rel="nofollow">http:&#x2F;&#x2F;kentonv.github.io&#x2F;capnproto&#x2F;</a>
评论 #7902400 未加载
评论 #7902285 未加载
评论 #7902462 未加载
kentonv将近 11 年前
Huh. So Google is releasing a competitor to Cap&#x27;n Proto. As the former maintainer of Protobufs (at Google) and author of Cap&#x27;n Proto (after Google), I&#x27;m pretty surprised that I hadn&#x27;t heard about this. I also don&#x27;t recognize any of the names, so this is not from the people who were working on Protobufs at the time I left.<p>I&#x27;m the main competitor, so take me with a grain of salt here.<p>The docs don&#x27;t look very detailed, but taking a quick look through...<p>&gt; &quot;On purpose, the format leaves a lot of details about where exactly things live in memory undefined, e.g. fields in a table can have any order... To be able to access fields regardless of these uncertainties, we go through a vtable of offsets. Vtables are shared between any objects that happen to have the same vtable values.&quot;<p>Hrm, that sounds like a lot of complexity and a big performance hit. In order to read a field from a struct, you have to do a vtable lookup to find the offset? Maybe you can still get that done in an inline accessor, but it will make the optimizer sad.<p>How is de-duping of vtables accomplished? It doesn&#x27;t look like the API exposes any details about vtables, meaning you&#x27;d have to do it magically behind the scenes, which seems expensive?<p>It looks like the authors may have been trying to maintain the concept of &quot;optional fields&quot; from Protobufs, where if you don&#x27;t set an optional field, it takes zero bytes on the wire. But the main use of optional fields in practice is to implement unions -- i.e. a list of fields where only one should be filled in at a time.<p>Cap&#x27;n Proto&#x27;s solution to this was just to build unions into the language, something Protobufs should have done a long time ago.<p>&gt; &quot;FlatBuffers relies on new field declarations being added at the end, and earlier declarations to not be removed, but be marked deprecated when needed. We think this is an improvement over the manual number assignment that happens in Protocol Buffers.&quot;<p>That&#x27;s not an improvement at all. Declarations should be ordered semantically, so that related things go together. More importantly, even if you say that they can&#x27;t be, developers will still do it, and will accidentally introduce incompatibilities. To make matters worse, it tends to be hard to detect these issues in testing, because your tests are probably build from the latest code. Simply adding field numbers as in Protobufs and Cap&#x27;n Proto has proven an effective solution to this in practice.<p>Very surprised to see Google get this wrong, since they have more experience with this than anyone.<p>&gt; Benchmarks<p>I couldn&#x27;t find the benchmark code in the github repo, so it&#x27;s hard to say what they may be measuring here. FlatBuffers presumably shares Cap&#x27;n Proto&#x27;s property that encodes and decodes take zero time, which makes it hard to create a meaningful benchmark in the first place. Indeed the numbers they put up kind of look like they&#x27;re timing a noop loop. I can&#x27;t see how the &quot;traverse&quot; time could be so much better than with protobufs, which makes me think the code might be written in such a way that the compiler was able to optimize away all the traverse time for FlatBuffers because it thought the results were unused anyway -- a mistake that&#x27;s easy to make.<p>But I&#x27;d love to see the code to verify. Hopefully I just missed it when digging through the repo.
评论 #7904708 未加载
评论 #7902519 未加载
评论 #7903176 未加载
评论 #7902549 未加载
评论 #7902524 未加载
评论 #7902768 未加载
评论 #7903557 未加载
评论 #7902850 未加载
ipkn将近 11 年前
If you don&#x27;t want the code generation step and C++ is the only language to use, Dumpable[1] can be useful.<p>[1]<a href="https://github.com/ipkn/dumpable" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ipkn&#x2F;dumpable</a>
emmelaich将近 11 年前
Just because I&#x27;m a fan of his, I&#x27;d like to point out that the author, Wouter van Oortmerssen aka Aardappel (strlen.com) is creator of the Cube 3d engine and lots of other interesting stuff.<p>Oh I&#x27;m also a fan of Kenton&#x27;s in case it matters :-)
评论 #7905820 未加载
clhodapp将近 11 年前
Their doc site doesn&#x27;t scroll in Chrome for Android, which seems a bit embarrassing if you&#x27;re Google.
评论 #7907304 未加载
mantraxB将近 11 年前
The problem with FlatBuffers and Cap&#x27;n Proto is that while in-memory rep matching serialization formats are much faster (infinitely faster as Cap&#x27;n Proto says tongue in cheek) for languages with unsafe direct memory access (like C&#x2F;C++), they&#x27;re actually slower and more cumbersome to use in any language without unsafe direct memory access (like Java, Rust, Python, Go, JavaScript&#x2F;Node, Swift and... well, most languages).<p>The other problem is that Google tends to release random stuff as open source and then modify it (breaking BC) or abandon it without regard for the people who are using it.<p>So caveat emptor, I guess.
评论 #7904532 未加载
评论 #7904741 未加载