Skip to content

Commit

Permalink
Use F14NodeMap for Protocol Object fields
Browse files Browse the repository at this point in the history
Summary:
`F14NodeMap` is a better choice since we don't know the field size in advance and this will not lead us to reallocate the values in map. In general we see improvement in deserialization and serialization. The extreme test case of `LargeMixed` show improvement in deserialization but regression in serialization but since deserialization is generally much slower than serialization (~x5), this is a fair trade-off.

benchmark result:
// More general -> ~34% improvement in deserialization of ComplexStruct
//                           -> Slight improvement in serialization in general
```
// before
=============================================================================================
fbcode/thrift/lib/cpp2/test/ProtocolBench.cpp     relative  time/iter   iters/s  serialized_size
=============================================================================================
ObjectBinaryProtocol_write_BigListMixed                                    659.54us     1.52K              NaN
ObjectBinaryProtocol_read_BigListMixed                                       3.11ms    322.00           500009
ObjectBinaryProtocol_write_BigListMixedInt                                   1.27ms    790.12              NaN
ObjectBinaryProtocol_read_BigListMixedInt                                    6.70ms    149.29           850009
ObjectBinaryProtocol_write_LargeMapMixed                                   145.46ms      6.87              NaN
ObjectBinaryProtocol_read_LargeMapMixed                                    655.77ms      1.52         54000010
ObjectBinaryProtocol_write_ComplexStruct                                   160.19ms      6.24              NaN
ObjectBinaryProtocol_read_ComplexStruct                                    876.82ms      1.14         59006614
ObjectCompactProtocol_write_BigListMixed                                   799.68us     1.25K              NaN
ObjectCompactProtocol_read_BigListMixed                                      3.85ms    259.58           300005
ObjectCompactProtocol_write_BigListMixedInt                                  1.77ms    563.70              NaN
ObjectCompactProtocol_read_BigListMixedInt                                   7.27ms    137.47           720005
ObjectCompactProtocol_write_LargeMapMixed                                  150.58ms      6.64              NaN
ObjectCompactProtocol_read_LargeMapMixed                                   687.48ms      1.45         32991750
ObjectCompactProtocol_write_ComplexStruct                                  177.33ms      5.64              NaN
ObjectCompactProtocol_read_ComplexStruct                                   846.40ms      1.18         38637929
=============================================================================================
```
```
// after
=============================================================================================
fbcode/thrift/lib/cpp2/test/ProtocolBench.cpp     relative  time/iter   iters/s  serialized_size
=============================================================================================
ObjectBinaryProtocol_write_BigListMixed                                    616.31us     1.62K              NaN
ObjectBinaryProtocol_read_BigListMixed                                       2.82ms    355.18           500009
ObjectBinaryProtocol_write_BigListMixedInt                                   1.35ms    738.65              NaN
ObjectBinaryProtocol_read_BigListMixedInt                                    7.88ms    126.87           850009
ObjectBinaryProtocol_write_LargeMapMixed                                   124.44ms      8.04              NaN
ObjectBinaryProtocol_read_LargeMapMixed                                    526.60ms      1.90         54000010
ObjectBinaryProtocol_write_ComplexStruct                                   128.39ms      7.79              NaN
ObjectBinaryProtocol_read_ComplexStruct                                    580.06ms      1.72         59006614
ObjectCompactProtocol_write_BigListMixed                                   743.84us     1.34K              NaN
ObjectCompactProtocol_read_BigListMixed                                      3.98ms    251.40           300005
ObjectCompactProtocol_write_BigListMixedInt                                  1.79ms    557.80              NaN
ObjectCompactProtocol_read_BigListMixedInt                                  10.49ms     95.34           720005
ObjectCompactProtocol_write_LargeMapMixed                                  126.08ms      7.93              NaN
ObjectCompactProtocol_read_LargeMapMixed                                   492.39ms      2.03         32991750
ObjectCompactProtocol_write_ComplexStruct                                  139.44ms      7.17              NaN
ObjectCompactProtocol_read_ComplexStruct                                   557.91ms      1.79         38637929
=============================================================================================
```

// LargeMixed -> ~37% improvement in deserialization and ~29% regression in serialization
```
// before
=============================================================================================
fbcode/thrift/lib/cpp2/test/ProtocolBench.cpp     relative  time/iter   iters/s  serialized_size
=============================================================================================
ObjectBinaryProtocol_write_LargeMixed                                        1.13us   888.40K              NaN
ObjectBinaryProtocol_read_LargeMixed                                         6.09us   164.27K              851
ObjectCompactProtocol_write_LargeMixed                                       1.50us   668.54K              NaN
ObjectCompactProtocol_read_LargeMixed                                        5.75us   174.04K              351
=============================================================================================
```
```
// after
=============================================================================================
fbcode/thrift/lib/cpp2/test/ProtocolBench.cpp     relative  time/iter   iters/s  serialized_size
=============================================================================================
ObjectBinaryProtocol_write_LargeMixed                                        1.46us   682.76K              NaN
ObjectBinaryProtocol_read_LargeMixed                                         3.84us   260.13K              851
ObjectCompactProtocol_write_LargeMixed                                       1.81us   550.97K              NaN
ObjectCompactProtocol_read_LargeMixed                                        3.96us   252.25K              351
=============================================================================================
```

Reviewed By: Mizuchi

Differential Revision: D62352362

fbshipit-source-id: d00cb613dba749bf9bc5f74bad58b408b1155ecc
  • Loading branch information
thedavekwon authored and facebook-github-bot committed Sep 9, 2024
1 parent 34c0a9b commit a9df464
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion thrift/lib/thrift/protocol_detail.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Object {
// The members of the object.
// TODO(ytj): use schema.FieldId as key
@cpp.Ref{type = cpp.RefType.Unique}
@cpp.Type{template = "::folly::F14FastMap"}
@cpp.Type{template = "::folly::F14NodeMap"}
2: map<i16, Value> members;
} (cpp.virtual, thrift.uri = "facebook.com/thrift/protocol/Object", rust.ord)

Expand Down

0 comments on commit a9df464

Please sign in to comment.