Schema Design for Optimal size

43 views
Skip to first unread message

bwo...@netflix.com

unread,
Jul 21, 2016, 6:48:47 PM7/21/16
to FlatBuffers
Hi,
I want to convert from my current storage of data using json to use flatbuffers. I am not seeing the saving that I am hoping for, though. I am seeing my flatbuffer data size(the underlying byte array that I am storing) is larger than the original json. I am guessing it has to do with my schema design. I think it's pretty simple but want to find out  for sure. I basically have an object that is made up of an array of lists , each list has an array of items. The schema I defined is here

namespace datatypes;




enum ObjectType : short {
        integer=1,
        longvalue,
        stringvalue,
        booleanvalue,
        shortvalue,
        doublevalue
}

table AnnotationFB{
    key:string;
    type:ObjectType=integer;
    valueint:int;
    valuelong:long;
    valuestring:string;
    valueboolean:bool;
    valueshort:short;
    valuedouble:double;
}

table ResponseFB {
  annotations:[AnnotationFB];
  lists:[ListFB];   // Vector of lists.

}
table ListFB {
  items:[ItemFB];
  annotations:[AnnotationFB];



}
table ItemFB {
  itemId:long;
  annotations:[AnnotationFB];

}

root_type ResponseFB;

Any suggestions are appreciated

Wouter van Oortmerssen

unread,
Jul 25, 2016, 1:42:47 PM7/25/16
to bwo...@netflix.com, FlatBuffers
Your schema is trying to emulate a dynamically typed JSON in FlatBuffers. FlatBuffers is intended to be used with strong typing.

Instead of storing a object like:

{ a: 1, b: 2 }

in an ItemFB (which costs you 3 tables, a vector, 2 strings, and several scalar fields), you want to define a specific object in the schema:

table MyTable { a:int; b:int; }

Which costs you 1 table and a few scalars.



--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bruce Wobbe

unread,
Jul 25, 2016, 2:01:35 PM7/25/16
to Wouter van Oortmerssen, FlatBuffers
That was what I was thinking. I thought maybe my Annotation table got around that, but no.

Thanks Again

Bruce
Reply all
Reply to author
Forward
0 new messages