Skip to content

Commit e41f730

Browse files
committed
Directly use TCMalloc rather than the system malloc on Linux.
This improve the toolchain's performance by about 10%. It will also allow us to leverage TCMalloc's extensions to do heap profiling and get other information about how efficiently we're using the heap. Note that currently this causes all of our builds to produce a warning due to an issue with `rules_python` and multiple modules registering python toolchains: bazel-contrib/rules_python#1818 This is also only enabled on Linux as there is no support for other OSes at the moment.
1 parent 2fcff24 commit e41f730

File tree

4 files changed

+143
-2
lines changed

4 files changed

+143
-2
lines changed

.bazelrc

+3
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ build --action_env=LANG=en_US.UTF-8
110110
build --enable_platform_specific_config
111111
build:linux --define=pfm=1
112112

113+
# Enable TCMalloc on Linux as well.
114+
build:linux --custom_malloc=@tcmalloc//tcmalloc
115+
113116
# Allow users to override any of the flags desired by importing a user-specific
114117
# RC file here if present.
115118
try-import %workspace%/user.bazelrc

MODULE.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ archive_override(
4343
urls = ["https://sourceforge.net/projects/perfmon2/files/libpfm4/libpfm-{0}.tar.gz".format(libpfm_version)],
4444
)
4545

46+
# The registry has a snapshot, but upstream is active and not regularly marking
47+
# releases. We start with the BCR snapshot to avoid a miss and then override it
48+
# with a more recent commit.
49+
bazel_dep(name = "tcmalloc", version = "0.0.0-20240411-5ed309d", dev_dependency = True)
50+
git_override(
51+
module_name = "tcmalloc",
52+
# HEAD as of 2024-07-14.
53+
commit = "923df94c922e0cd2d0512c1662d374f63c2c0c96",
54+
remote = "https://github.com/google/tcmalloc.git",
55+
)
56+
4657
bazel_dep(name = "rules_bison", version = "0.2.2")
4758
bazel_dep(name = "rules_flex", version = "0.2.1")
4859
bazel_dep(name = "rules_m4", version = "0.2.3")

MODULE.bazel.lock

+125-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel/cc_toolchains/clang_cc_toolchain_config.bzl

+4-1
Original file line numberDiff line numberDiff line change
@@ -1076,10 +1076,13 @@ def _impl(ctx):
10761076
target_system_name = identifier,
10771077
target_cpu = ctx.attr.target_cpu,
10781078

1079+
# This is used to expose a "flag" that `config_setting` rules can use to
1080+
# determine if the compiler is Clang.
1081+
compiler = "clang",
1082+
10791083
# These attributes aren't meaningful at all so just use placeholder
10801084
# values.
10811085
target_libc = "local",
1082-
compiler = "local",
10831086
abi_version = "local",
10841087
abi_libc_version = "local",
10851088

0 commit comments

Comments
 (0)