reserve capacity in toAppend<StringType>(...)
authorMarcin Pawlowski <mpawlowski@fb.com>
Tue, 15 Jul 2014 22:30:57 +0000 (15:30 -0700)
committerTudor Bosman <tudorb@fb.com>
Mon, 21 Jul 2014 19:22:03 +0000 (12:22 -0700)
commitb6a8eb2e3e7dae0c48cf1ace5299bc777b2753cd
treea9e5b80eb149bf1eb68d59891491774df40da4f3
parent28a34a4e25f909d14639134701baaebc48524b0c
reserve capacity in toAppend<StringType>(...)

Summary:
I modified the toAppend(args..., StringType* dest) so that
before appending it reserves enough space for data to be appended. It is
still work in progress (floats and doubles are really bad: we only do
very naive approximation of the size). On float like workload we gain
~10% perf, on strings/ints/chars we gain as much as 25% of perf.
Probably on bigger strings it will be even faster. We only modify the
case when toAppend() has more than 1 element to append as it would be
just overhead in case of one argument.

Test Plan:
with this change:

============================================================================
folly/test/ConvTest.cpp                         relative  time/iter
iters/s
============================================================================
preallocateTestNoFloat                                       1.59us 627.85K
preallocateTestFloat                                         1.09us 920.70K
----------------------------------------------------------------------------
============================================================================

without the change:

============================================================================
folly/test/ConvTest.cpp                         relative  time/iter
iters/s
============================================================================
preallocateTestNoFloat                                       2.12us 471.43K
preallocateTestFloat                                         1.22us 818.25K
----------------------------------------------------------------------------
============================================================================

Reviewed By: marcelo.juchem@fb.com

FB internal diff: D1420588

Tasks: 4632421
folly/Conv.h
folly/test/ConvTest.cpp