Faster repeated append (particularly for short strings)
authorAndrei Alexandrescu <aalexandre@fb.com>
Fri, 10 Aug 2012 16:50:15 +0000 (09:50 -0700)
committerTudor Bosman <tudorb@fb.com>
Sun, 26 Aug 2012 18:12:51 +0000 (11:12 -0700)
commitc3f47cdcfd4d4d23e20168c60fd73168c4603e9f
treef2d6a966cd91a5394b6ddac22228204070c182f3
parent442e1c0c6ffebf233bae7367bc49a4d90c149b0b
Faster repeated append (particularly for short strings)

Summary:
https://phabricator.fb.com/D544159 reveals a large performance gap between
fbstring and std::string for repeated appends of short strings, which I
consider a relatively urgent matter (as much of our code uses such patterns).

This diff attempts to fix the issue in a principled manner by first appending
the first character with exponential reallocation, after which the rest of the
characters are appended normally.

With the proposed fix the benchmarks are much faster than the previous fbstring
and also than std::string (numbers to follow in comments).

Test Plan: unittested and benchmarked

Reviewed By: soren@fb.com

FB internal diff: D545416
folly/FBString.h