DB::Put() to estimate write batch data size needed and pre-allocate buffer

Summary:
In one of CPU profiles, we see some CPU costs of string::reserve() inside Batch.Put(). This patch should be able to reduce some of the costs by allocating sufficient buffer before hand.

Since it is a trivial percentage of CPU costs, I didn't find a way to show the improvement in one of the benchmarks. I'll deploy it to same application and do the same CPU profiling to make sure those CPU costs are reduced.

Test Plan: make all check

Reviewers: haobo, kailiu, igor

Reviewed By: haobo

CC: leveldb, nkg-

Differential Revision: https://reviews.facebook.net/D15135
This commit is contained in:
Siying Dong
2014-01-14 10:42:36 -08:00
parent ac2fe72832
commit 51dd21926c
3 changed files with 7 additions and 3 deletions

View File

@@ -35,7 +35,7 @@ struct SliceParts;
class WriteBatch {
public:
WriteBatch();
explicit WriteBatch(size_t reserved_bytes = 0);
~WriteBatch();
// Store the mapping "key->value" in the database.