my tcmalloc test tcmalloc is 10x slow than glibc! Appreciate it for you advise!
kungf opened this issue · comments
wyang commented
Test code was built with bazel, and the result:
glibc run-time 273900440ns
tcmalloc run-time 3360949905 ns
tcmalloc is 10+ slow than glibc, it's so confusing for me!
Is anything wrong with my build?
Thank you very much for your help!!
test code:
#include <iostream>
#include <chrono>
class A {
public:
A():a(32){}
int64_t a;
};
void test() {
A *cs = new A();
delete cs;
}
int main() {
auto start_time = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 10000000; i++) {
test();
}
auto end_time = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time);
std::cout << "time " << duration.count() << std::endl;
return 0;
}
WORKSPACE
local_repository(
# Name of the TCMalloc repository. This name is defined within your
# WORKSPACE file, in its `workspace()` metadata
name = "com_google_tcmalloc",
# NOTE: Bazel paths must be absolute paths. E.g., you can't use ~/Source
path = "/home/tcmalloc-bazel",
)
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Abseil
http_archive(
name = "com_google_absl",
urls = ["https://github.com/abseil/abseil-cpp/archive/a3020c763c12bd16bbf00804abe853afa5778174.zip"],
strip_prefix = "abseil-cpp-a3020c763c12bd16bbf00804abe853afa5778174",
sha256 = "0b0cd6cacd754b88cfc098e8a87a6e00f1ea5833ebf0c34738dfb9357345b13c",
)
# Fuzzing
http_archive(
name = "rules_fuzzing",
sha256 = "a5734cb42b1b69395c57e0bbd32ade394d5c3d6afbfe782b24816a96da24660d",
strip_prefix = "rules_fuzzing-0.1.1",
urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.1.1.zip"],
)
# Protobuf
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
rules_fuzzing_dependencies()
load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init")
rules_fuzzing_init()
WORKSPACE
cc_binary(
name = "hello_world",
srcs = ["hello_world.cc"],
malloc = "@com_google_tcmalloc//tcmalloc",
)
Chris Kennelly commented
CorrectSize
is a debug assertion used to verify that the right size is being passed to sized delete. It appears to be where most of your time is going in the flame graph.
If you do an optimized build (-c opt
with Bazel), these assertions will be compiled out.