thriftrw / thriftrw-python

A Thrift encoding library for Python
MIT License
36 stars 10 forks source link

Optimize serialization path further. #138

Closed clin88 closed 7 years ago

clin88 commented 8 years ago

Optimize serialization by eliminating unnecessary python interaction. This speeds up serialization by an order of magnitude, bringing mean struct serialization speed down to 606us from 2300.

Before

---------------------------------------------------------------------- benchmark: 8 tests ---------------------------------------------------------------------
Name (time in us)                                      Min           Max          Mean       StdDev        Median          IQR  Outliers(*)  Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------
test_binary_dumps[nested_structs]               2,081.1558    3,769.8746    2,299.1417     176.8170    2,246.4991     113.2488        40;29     458           1
test_binary_dumps[primitive_containers]        55,597.0669   73,477.9835   60,404.3007   5,612.7009   58,637.9766   5,454.0634          2;2      14           1
test_binary_loads[nested_structs]               8,927.1069   24,309.1583   10,061.6861   2,602.2951    9,428.0243     676.0359          3;7      87           1
test_binary_loads[primitive_containers]        82,612.0377   88,231.0867   85,562.8360   2,014.2171   85,551.9772   3,880.0836          6;0      11           1

After

---------------------------------------------------------------------- benchmark: 8 tests ---------------------------------------------------------------------
Name (time in us)                                      Min           Max          Mean       StdDev        Median          IQR  Outliers(*)  Rounds  Iterations
---------------------------------------------------------------------------------------------------------------------------------------------------------------
test_binary_dumps[nested_structs]                 535.9650    1,294.8513      606.5146      95.4681      568.1515      88.6917      242;116    1743           1
test_binary_dumps[primitive_containers]        36,353.1113   55,827.1408   42,985.3743   4,252.7771   42,118.0725   5,695.8199          6;1      22           1
test_binary_loads[nested_structs]               4,865.1695   22,401.0944    5,859.4299   2,367.5030    5,295.9919     680.5062         3;15     139           1
test_binary_loads[primitive_containers]        86,452.9610  105,139.9708   89,878.9167   5,444.1895   88,407.9933   1,445.7703          1;1      10           1
coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.2%) to 74.266% when pulling 05e05d25403db3dc67f85bbf29ee534f72c86796 on saveopt2 into 4a6029b51e70d65568e42665184bc35aa578f46f on master.

HelloGrayson commented 8 years ago

As fantarstic (not a typo) as I think this is - I think we should get @abhinav's eyes on here before landing.

Most performance optimizations come with the tradeoff of limiting the flexibility of existing APIs - something that is likely well worth it, but I'd still like the primary author of this repo to sign-off.

HelloGrayson commented 8 years ago

Hard to argue with that :)

For the record, I meant when @abhinav was back from vacay :D

clin88 commented 7 years ago

@abhinav This is actually a 16x improvement compared to before we started optimizing, which puts us on par with the c implementation.