rocksdb
rocksdb copied to clipboard
Avoid dynamic memory allocation on read path
Summary: lambda function dynamicly allocates memory from heap if it needs to capture multiple values, which could be expensive. Switch to explictly use local functor from stack.
Test Plan: CI db_bench shows ~2-3% read improvement:
# before the change
TEST_TMPDIR=/tmp/dbbench4 ./db_bench_main --benchmarks=filluniquerandom,readrandom -compression_type=none -max_background_jobs=12 -num=10000000
readrandom : 8.528 micros/op 117265 ops/sec 85.277 seconds 10000000 operations; 13.0 MB/s (10000000 of 10000000 found)
# after the change
TEST_TMPDIR=/tmp/dbbench5 ./db_bench_new --benchmarks=filluniquerandom,readrandom -compression_type=none -max_background_jobs=12 -num=10000000
readrandom : 8.263 micros/op 121015 ops/sec 82.634 seconds 10000000 operations; 13.4 MB/s (10000000 of 10000000 found)
details: https://gist.github.com/jay-zhuang/5ac0628db8fc9cbcb499e056d4cb5918
Micro-benchmark shows a similar improvement ~1-2%: before the change: https://gist.github.com/jay-zhuang/9dc0ebf51bbfbf4af82f6193d43cf75b after the change: https://gist.github.com/jay-zhuang/fc061f1813cd8f441109ad0b0fe7c185
@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@jay-zhuang has updated the pull request. You must reimport the pull request before landing.
@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@jay-zhuang has updated the pull request. You must reimport the pull request before landing.
@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.
@jay-zhuang has updated the pull request. You must reimport the pull request before landing.
Updated to #10562