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
Showing
Please register or sign in to comment