Repository navigation
Fix MinGW Clang DLL build while preserving thread-local caching - #1990
Conversation
72488fd to
f63cf49
Compare
|
@StableAgOH Can you benchmark the performance difference? The reason for |
|
@an-tao @marty1885 我做了benchmark。
测试源码: // test.cc
//静态链接trantor,动态链接benchmark
//static link against libtrantor.a, dynamic link against libbenchmark.dll
#define TRANTOR_STATIC_DEFINE
#include <cassert>
#include <trantor/utils/Utilities.h>
#include <benchmark/benchmark.h>
namespace A {
namespace B {
std::string former(size_t size) { /* thread_local */ }
std::string later(size_t size) {/* this PR change */}
} // namespace B
} // namespace A
static void BM_former(benchmark::State& state) {
for(auto _: state) {
auto s = A::B::former(static_cast<size_t>(state.range(0)));
benchmark::DoNotOptimize(s);
}
}
static void BM_later(benchmark::State& state) {
for(auto _: state) {
auto s = A::B::later(static_cast<size_t>(state.range(0)));
benchmark::DoNotOptimize(s);
}
}
BENCHMARK(BM_former)->Arg(16)->Arg(64)->Arg(256)->Arg(1024);
BENCHMARK(BM_later)->Arg(16)->Arg(64)->Arg(256)->Arg(1024);
BENCHMARK_MAIN(); 输出结果result: |
|
看起来生成短字符更慢了 |
Thanks for the benchmark. I've updated this PR with a smaller fix: moving the TLS declarations outside the lambda while preserving cross-call caching. I compared all three implementations on Windows 11, Ryzen 7 9800X3D, Clang 23.1.3 (MSYS2 UCRT64), using Trantor 1.5.29 with OpenSSL 3.6.5 and Google Benchmark 1.10.0 ( Single-thread median wall-clock time over 7 randomly interleaved repetitions:
The updated version avoids the short-string regression seen in the previous PR version. |
Fix #1845.