Improve performance of stringPrintf and related functions
Summary:
It turned out at least one optimization we were doing for
stringPrintf (using the tail of the input buffer) was causing a
performance degradation in some cases -- if the string was already
pre-sized, our resize() call would end up memset'ing the tail. In some
instances, this could cause significant performance penalties, such as
when multiple stringAppendf calls were made.
So, this diff removes the "optimization" around using the tail of the input
buffer and instead uses a standalone stack buffer. If vsnprintf deems
that buffer too small, a heap buffer is instead used.
As there is no std::string method that resizes the string to fill the
underlying buffer without setting the values to a default, and as it is
not legal to write past the end of the data buffer (even if capacity()
says there is enough), let's just abandon that optimization. It turns
out this doesn't have a major performance loss for most cases since,
with this diff, most small strings will fit on-stack and then hopefully
in the string's tail anyway.
Test Plan: runtests
Reviewed By: simpkins@fb.com
Subscribers: trunkagent, net-systems@, lins, anca, folly-diffs@
FB internal diff:
D1733774
Tasks:
5735468
Signature: t1:
1733774:
1418323943:
ec47007c9756aca6cf0466bce92722ac4c7e89b2