[libcxx-commits] [libcxx] [libc++] Fix "leak" of PMR resource in benchmark (PR #216114)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Aug 13 09:47:22 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Louis Dionne (ldionne)
<details>
<summary>Changes</summary>
The benchmark was not releasing the monotonic buffer resource, which means we'd grow a larger and larger pool as Google Benchmark would go through more and more iterations of the benchmark.
As a drive-by, it also fixes an incorrect `DoNotOptimize(c + i)` that was called on the wrong pointer (c is a pointer to bytes).
---
Full diff: https://github.com/llvm/llvm-project/pull/216114.diff
1 Files Affected:
- (modified) libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h (+7-4)
``````````diff
diff --git a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
index 34cd1ca90b647..4eaac2bff038b 100644
--- a/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
+++ b/libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h
@@ -147,18 +147,21 @@ void associative_container_benchmarks(std::string container) {
std::pmr::monotonic_buffer_resource rs2(size * 64 * BatchSize); // 64 bytes should be enough per node
while (st.KeepRunningBatch(BatchSize)) {
for (std::size_t i = 0; i != BatchSize; ++i) {
- new (c + i * sizeof(PMRContainer)) PMRContainer(std::move(srcs[i]), &rs2);
- benchmark::DoNotOptimize(c + i);
+ PMRContainer* p = reinterpret_cast<PMRContainer*>(c) + i;
+ new (p) PMRContainer(std::move(srcs[i]), &rs2);
+ benchmark::DoNotOptimize(p);
benchmark::ClobberMemory();
}
st.PauseTiming();
for (std::size_t i = 0; i != BatchSize; ++i) {
- reinterpret_cast<PMRContainer*>(c + i * sizeof(PMRContainer))->~PMRContainer();
+ PMRContainer* p = reinterpret_cast<PMRContainer*>(c) + i;
+ p->~PMRContainer();
}
rs2.release();
srcs.clear();
- for (size_t i = 0; i != BatchSize; ++i)
+ rs.release();
+ for (std::size_t i = 0; i != BatchSize; ++i)
srcs.emplace_back(&rs).insert(in.begin(), in.end());
st.ResumeTiming();
``````````
</details>
https://github.com/llvm/llvm-project/pull/216114
More information about the libcxx-commits
mailing list