mzaks / FlatBuffersSwift

This project brings FlatBuffers (an efficient cross platform serialization library) to Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document deserialization modes

tamastimar opened this issue · comments

There are 3 ways to access data from binary:

  • Class.fromByteArray(),
  • Class.LazyAccess()
  • and Class.Fast().

The wiki explains that the whole object is not deserialized by using LazyAcess. But what about Fast? How does it differ from the others?

It'd be nice to document somewhere the differences between them.

Anyway, thanks for your work! 👍

Yes sorry the Wiki is out of date specifically in regards to latest version with Swift3 support.
I will update it ASAP.
Or you already using it and want to know how it is different for the old version?

Currently I'm using 1.1.4 to be compatible with Swift 2.3. I can see those 3 deserialization options in that version. So I think my question is not releated to the Swift 3 version.

I implemented LazyAccess so that the values will be read out of the buffer only on demand and than will be stored so if you need to access the value again, it is already in memory. That sounded like a good idea at the time. However when @hassila ported the performance tests from Flatbuffers project, it become clear that the Lazy concept is performance wise not a good idea. Mainly because if you want to have fast access to values you should keep everything on the stack. This is how Fast was born. With Fast you get a struct which knows how to retrieve the values and stores nothing itself. This is why it can stay on the stack and provides the best performance characteristics.
May I ask in which scenario you use FlatBuffers. I am asking because I had some issues in production which I fixed. Those issues are fixed in the Swift3 version, but I am not 100% sure if they are fixed in the latest 2.3 version.

With Fast you get a struct which knows how to retrieve the values and stores nothing itself. This is why it can stay on the stack and provides the best performance characteristics.

So is there any situation when using LazyAccess makes sense?

May I ask in which scenario you use FlatBuffers.

What do you think exactly?

With Fast working well, LazyAccess does not make sense any more.

I mean if you use it for BackEnd client communication or for serialising state of your App. Is it a mobile App or desktop.
I had a problem with mobile App running on amrv7 => iPhone4S and older, iPad 4 and older.
The problem was occurred because in old implementations of FlatBuffersSwift I made memory alignment optional. This how ever lead to problem on old devices in release build.
In the Swift3 version of FlatBuffersSwift memory alignment is always on.

I use it on iOS but currently deserializing the whole object. So I can't tell you if there is any problem or not in Fast.

Could you tell me what kind of problem should be aware of in the future if I'd switch to Fast?

If you hit the problem, the deserialisation will crash. No matter which method sou use. So the bug was actually in the serialisation code FlatBufferBuilder not in the deserialisation.