rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

Avoid dynamic memory allocation on read path

Open jay-zhuang opened this issue 2 years ago • 5 comments

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 avatar Aug 01 '22 19:08 jay-zhuang

@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Aug 02 '22 05:08 facebook-github-bot

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Aug 02 '22 16:08 facebook-github-bot

@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Aug 02 '22 16:08 facebook-github-bot

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Aug 08 '22 18:08 facebook-github-bot

@jay-zhuang has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

facebook-github-bot avatar Aug 08 '22 18:08 facebook-github-bot

@jay-zhuang has updated the pull request. You must reimport the pull request before landing.

facebook-github-bot avatar Aug 23 '22 22:08 facebook-github-bot

Updated to #10562

jay-zhuang avatar Aug 23 '22 23:08 jay-zhuang