Optimize fbstring::append()
authorGiuseppe Ottaviano <ott@fb.com>
Mon, 21 Mar 2016 03:34:23 +0000 (20:34 -0700)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Mon, 21 Mar 2016 03:35:20 +0000 (20:35 -0700)
commit60088aaa3981d97f303a079b500dd03e2ae966b7
tree8fe13f1049e7d1f5cc1582eeeb57cd47065f2238
parentd05711c657c2054a9dd6f77f262823541061f094
Optimize fbstring::append()

Summary:Instead of relying on `push_back()` to guarantee exponential growth,
delegate to `expand_noinit`. This removes the duplication of logic
between the two functions, and significantly speeds up short appends.

```
$ _bin/folly/test/fbstring_benchmark_using_jemalloc --bm_min_usec=100000
                                                          Before:             After:
============================================================================ ===================
./folly/test/FBStringTestBenchmarks.cpp.h       relative  time/iter  iters/s  time/iter  iters/s
============================================================================ ===================
...
BM_push_back_fbstring(1)                                     7.51ns  133.20M     6.87ns  145.49M
BM_push_back_fbstring(23)                                  175.08ns    5.71M   173.92ns    5.75M
BM_push_back_fbstring(127)                                 586.02ns    1.71M   585.70ns    1.71M
BM_push_back_fbstring(1024)                                  3.30us  302.81K     3.41us  293.13K
BM_short_append_fbstring(23)                               367.01ns    2.72M   179.45ns    5.57M
BM_short_append_fbstring(1024)                               9.33us  107.20K     5.72us  174.95K
...
============================================================================ ===================
```

Reviewed By: philippv

Differential Revision: D3075249

fb-gh-sync-id: 497775ba3fc707bf50821a3cf10fb9d247b9352d
shipit-source-id: 497775ba3fc707bf50821a3cf10fb9d247b9352d
folly/FBString.h