Faster vom encoding and decoding.
This CL implements a collection of changes that speeds up both
vom encoding and decoding:
1) Use struct field indices rather than names. This avoids map
lookups in the common case, which gives a big win.
2) Cleanup and simplify the core uint decoding routines. We had
added many variants of these routines to handle control codes,
peeking rather than reading, and decoding from byte slices rather
than decbuf. This CL boils it down to a much smaller set of
methods, and speeds up each of those by using the new decbuf API
described next.
3) Faster decbuf API. Go only inlines short functions that don't
themselves call other functions, and inlining makes a huge
difference for the core decoding routines. The new API factors
things such that all of the common-case code is inlined.
4) Add a better fastpath for ReadValue* for decoding. This is
the codepath taken for decoding struct and union fields, and in
the common case where the type of the serialized bytes is
identical to the type we're decoding into, we can avoid all
extraneous work.
5) Use the unsafe package to avoid a copy when decoding strings.
There are more optimizations to be made for the encoder, and we
might consider using enum label indices rather than strings for a
similar gain. Those will come separately.
The numbers are below. Note that some of the "Zero" cases got
much worse; I'm not worrying about it since the absolute times
are still pretty low, and we can deal with specific Zero
optimizations separately.
benchmark old ns/op new ns/op delta
Vom___DecodeMany_XNumber 516 532 +3.10%
Vom___DecodeMany_VNumber 290 262 -9.66%
Vom___DecodeMany_XStringSmall 744 643 -13.58%
Vom___DecodeMany_VStringSmall 409 358 -12.47%
Vom___DecodeMany_XStringLarge 32310 18983 -41.25%
Vom___DecodeMany_VStringLarge 31709 18030 -43.14%
Vom___DecodeMany_VEnum 330 293 -11.21%
Vom___DecodeMany_XByteListSmall 821 774 -5.72%
Vom___DecodeMany_VByteListSmall 468 464 -0.85%
Vom___DecodeMany_XByteListLarge 19163 19376 +1.11%
Vom___DecodeMany_VByteListLarge 18061 18388 +1.81%
Vom___DecodeMany_XByteArray 796 759 -4.65%
Vom___DecodeMany_VByteArray 387 376 -2.84%
Vom___DecodeMany_XArray 848 789 -6.96%
Vom___DecodeMany_VArray 481 434 -9.77%
Vom___DecodeMany_XListSmall 1157 1151 -0.52%
Vom___DecodeMany_VListSmall 570 498 -12.63%
Vom___DecodeMany_XListLarge 3522243 2550194 -27.60%
Vom___DecodeMany_VListLarge 2453626 1267771 -48.33%
Vom___DecodeMany_XListAnySmall 2913 2872 -1.41%
Vom___DecodeMany_VListAnySmall 1634 1547 -5.32%
Vom___DecodeMany_XListAnyLarge 35741635 34369621 -3.84%
Vom___DecodeMany_VListAnyLarge 24464561 26419889 +7.99%
Vom___DecodeMany_VSet 1148 1003 -12.63%
Vom___DecodeMany_XMap 3175 2792 -12.06%
Vom___DecodeMany_VMap 1312 1104 -15.85%
Vom___DecodeMany_XSmallStruct 2534 1594 -37.10%
Vom___DecodeMany_VSmallStruct 856 602 -29.67%
Vom___DecodeMany_XLargeStruct 30923 8442 -72.70%
Vom___DecodeMany_VLargeStruct 5944 2740 -53.90%
Vom___DecodeMany_XLargeStructZero 878 860 -2.05%
Vom___DecodeMany_VLargeStructZero 424 391 -7.78%
Vom___DecodeMany_VSmallUnion 1355 1168 -13.80%
Vom___DecodeMany_Time 1755 1677 -4.44%
Vom___DecodeMany_Blessings 54516 53270 -2.29%
Vom___DecodeMany_RPCRequestZero 492 565 +14.84%
Vom___DecodeMany_RPCRequestFull 55682 53923 -3.16%
Vom___DecodeMany_RPCResponseZero 481 590 +22.66%
Vom___DecodeMany_RPCResponseFull 41434 39328 -5.08%
Vom___Decode_____XNumber 1301 1309 +0.61%
Vom___Decode_____VNumber 881 880 -0.11%
Vom___Decode_____XStringSmall 1429 1396 -2.31%
Vom___Decode_____VStringSmall 1039 954 -8.18%
Vom___Decode_____XStringLarge 33067 19657 -40.55%
Vom___Decode_____VStringLarge 32185 18628 -42.12%
Vom___Decode_____VEnum 907 882 -2.76%
Vom___Decode_____XByteListSmall 1575 1525 -3.17%
Vom___Decode_____VByteListSmall 1082 1087 +0.46%
Vom___Decode_____XByteListLarge 19933 19912 -0.11%
Vom___Decode_____VByteListLarge 18839 18905 +0.35%
Vom___Decode_____XByteArray 1581 1522 -3.73%
Vom___Decode_____VByteArray 966 948 -1.86%
Vom___Decode_____XArray 1831 1711 -6.55%
Vom___Decode_____VArray 1227 1160 -5.46%
Vom___Decode_____XListSmall 2122 2113 -0.42%
Vom___Decode_____VListSmall 1307 1200 -8.19%
Vom___Decode_____XListLarge 3380767 2520905 -25.43%
Vom___Decode_____VListLarge 2453680 1251395 -49.00%
Vom___Decode_____XListAnySmall 4210 4113 -2.30%
Vom___Decode_____VListAnySmall 2701 2617 -3.11%
Vom___Decode_____XListAnyLarge 37350228 36966199 -1.03%
Vom___Decode_____VListAnyLarge 26369538 25015060 -5.14%
Vom___Decode_____VSet 1956 1794 -8.28%
Vom___Decode_____XMap 4132 3798 -8.08%
Vom___Decode_____VMap 2156 1910 -11.41%
Vom___Decode_____XSmallStruct 3542 2536 -28.40%
Vom___Decode_____VSmallStruct 1684 1406 -16.51%
Vom___Decode_____XLargeStruct 33490 9621 -71.27%
Vom___Decode_____VLargeStruct 7075 3747 -47.04%
Vom___Decode_____XLargeStructZero 2120 2004 -5.47%
Vom___Decode_____VLargeStructZero 1426 1352 -5.19%
Vom___Decode_____VSmallUnion 2444 2180 -10.80%
Vom___Decode_____Time 2662 2570 -3.46%
Vom___Decode_____Blessings 57429 55326 -3.66%
Vom___Decode_____RPCRequestZero 1883 1938 +2.92%
Vom___Decode_____RPCRequestFull 58022 56356 -2.87%
Vom___Decode_____RPCResponseZero 1877 2040 +8.68%
Vom___Decode_____RPCResponseFull 45224 42712 -5.55%
Vom___EncodeMany_XNumber 419 414 -1.19%
Vom___EncodeMany_VNumber 155 155 +0.00%
Vom___EncodeMany_XStringSmall 429 437 +1.86%
Vom___EncodeMany_VStringSmall 172 160 -6.98%
Vom___EncodeMany_XStringLarge 23602 8093 -65.71%
Vom___EncodeMany_VStringLarge 23084 8007 -65.31%
Vom___EncodeMany_VEnum 165 165 +0.00%
Vom___EncodeMany_XByteListSmall 451 440 -2.44%
Vom___EncodeMany_VByteListSmall 166 162 -2.41%
Vom___EncodeMany_XByteListLarge 8084 7798 -3.54%
Vom___EncodeMany_VByteListLarge 7648 7723 +0.98%
Vom___EncodeMany_XByteArray 669 658 -1.64%
Vom___EncodeMany_VByteArray 182 184 +1.10%
Vom___EncodeMany_XArray 592 610 +3.04%
Vom___EncodeMany_VArray 257 260 +1.17%
Vom___EncodeMany_XListSmall 621 631 +1.61%
Vom___EncodeMany_VListSmall 270 271 +0.37%
Vom___EncodeMany_XListLarge 3153432 3169541 +0.51%
Vom___EncodeMany_VListLarge 2110173 2096758 -0.64%
Vom___EncodeMany_XListAnySmall 6186 6067 -1.92%
Vom___EncodeMany_VListAnySmall 5047 4895 -3.01%
Vom___EncodeMany_XListAnyLarge 144857440 141422491 -2.37%
Vom___EncodeMany_VListAnyLarge 134381574 134091980 -0.22%
Vom___EncodeMany_VSet 408 385 -5.64%
Vom___EncodeMany_XMap 2382 2306 -3.19%
Vom___EncodeMany_VMap 493 487 -1.22%
Vom___EncodeMany_XSmallStruct 1518 1319 -13.11%
Vom___EncodeMany_VSmallStruct 375 329 -12.27%
Vom___EncodeMany_XLargeStruct 25430 11837 -53.45%
Vom___EncodeMany_VLargeStruct 8621 2293 -73.40%
Vom___EncodeMany_XLargeStructZero 15917 9064 -43.05%
Vom___EncodeMany_VLargeStructZero 204 205 +0.49%
Vom___EncodeMany_VSmallUnion 210 210 +0.00%
Vom___EncodeMany_Time 1582 1583 +0.06%
Vom___EncodeMany_Blessings 4870 4295 -11.81%
Vom___EncodeMany_RPCRequestZero 194 200 +3.09%
Vom___EncodeMany_RPCRequestFull 4542 3863 -14.95%
Vom___EncodeMany_RPCResponseZero 549 593 +8.01%
Vom___EncodeMany_RPCResponseFull 39815 40801 +2.48%
Vom___Encode_____XNumber 3969 3785 -4.64%
Vom___Encode_____VNumber 3338 3201 -4.10%
Vom___Encode_____XStringSmall 3958 3787 -4.32%
Vom___Encode_____VStringSmall 3354 3209 -4.32%
Vom___Encode_____XStringLarge 59871 45504 -24.00%
Vom___Encode_____VStringLarge 59339 44453 -25.09%
Vom___Encode_____VEnum 4081 3842 -5.86%
Vom___Encode_____XByteListSmall 4210 4059 -3.59%
Vom___Encode_____VByteListSmall 3484 3397 -2.50%
Vom___Encode_____XByteListLarge 45808 46017 +0.46%
Vom___Encode_____VByteListLarge 44811 44857 +0.10%
Vom___Encode_____XByteArray 4536 4375 -3.55%
Vom___Encode_____VByteArray 3580 3483 -2.71%
Vom___Encode_____XArray 4539 4393 -3.22%
Vom___Encode_____VArray 3785 3647 -3.65%
Vom___Encode_____XListSmall 4522 4374 -3.27%
Vom___Encode_____VListSmall 3750 3625 -3.33%
Vom___Encode_____XListLarge 3344065 3333010 -0.33%
Vom___Encode_____VListLarge 2294181 2296135 +0.09%
Vom___Encode_____XListAnySmall 10908 10596 -2.86%
Vom___Encode_____VListAnySmall 9623 9218 -4.21%
Vom___Encode_____XListAnyLarge 150154031 148440574 -1.14%
Vom___Encode_____VListAnyLarge 140397260 141110872 +0.51%
Vom___Encode_____VSet 3990 4115 +3.13%
Vom___Encode_____XMap 6847 6517 -4.82%
Vom___Encode_____VMap 4385 4147 -5.43%
Vom___Encode_____XSmallStruct 7481 6904 -7.71%
Vom___Encode_____VSmallStruct 5740 5315 -7.40%
Vom___Encode_____XLargeStruct 44549 29674 -33.39%
Vom___Encode_____VLargeStruct 26891 18749 -30.28%
Vom___Encode_____XLargeStructZero 34969 25891 -25.96%
Vom___Encode_____VLargeStructZero 18380 16568 -9.86%
Vom___Encode_____VSmallUnion 5218 4916 -5.79%
Vom___Encode_____Time 6901 6610 -4.22%
Vom___Encode_____Blessings 31926 30306 -5.07%
Vom___Encode_____RPCRequestZero 38502 36148 -6.11%
Vom___Encode_____RPCRequestFull 46935 43710 -6.87%
Vom___Encode_____RPCResponseZero 39865 37641 -5.58%
Vom___Encode_____RPCResponseFull 89045 92906 +4.34%
MultiPart: 4/4
Change-Id: I23f0f5529eaff20d000880248e3a599113c6c166
1 file changed