Skip to content

Commit eafff7e

Browse files
committed
Directly use TCMalloc rather than the system malloc.
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
1 parent 2fcff24 commit eafff7e

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
@@ -35,6 +35,9 @@ build:clang-tidy --copt=-Wno-unknown-pragmas
3535
build --flag_alias=use_target_config_carbon_rules=//bazel/carbon_rules:use_target_config_carbon_rules
3636
build --use_target_config_carbon_rules
3737

38+
# Use TCMalloc by default.
39+
build --custom_malloc=@tcmalloc//tcmalloc
40+
3841
# Default to using a disk cache to minimize re-building LLVM and Clang which we
3942
# try to avoid updating too frequently to minimize rebuild cost. The location
4043
# here can be overridden in the user configuration where needed.

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)