Skip to content

Commit

Permalink
Directly use TCMalloc rather than the system malloc.
Browse files Browse the repository at this point in the history
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:
bazelbuild/rules_python#1818
  • Loading branch information
chandlerc committed Jul 15, 2024
1 parent 2fcff24 commit eafff7e
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ build:clang-tidy --copt=-Wno-unknown-pragmas
build --flag_alias=use_target_config_carbon_rules=//bazel/carbon_rules:use_target_config_carbon_rules
build --use_target_config_carbon_rules

# Use TCMalloc by default.
build --custom_malloc=@tcmalloc//tcmalloc

# Default to using a disk cache to minimize re-building LLVM and Clang which we
# try to avoid updating too frequently to minimize rebuild cost. The location
# here can be overridden in the user configuration where needed.
Expand Down
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ archive_override(
urls = ["https://sourceforge.net/projects/perfmon2/files/libpfm4/libpfm-{0}.tar.gz".format(libpfm_version)],
)

# The registry has a snapshot, but upstream is active and not regularly marking
# releases. We start with the BCR snapshot to avoid a miss and then override it
# with a more recent commit.
bazel_dep(name = "tcmalloc", version = "0.0.0-20240411-5ed309d", dev_dependency = True)
git_override(
module_name = "tcmalloc",
# HEAD as of 2024-07-14.
commit = "923df94c922e0cd2d0512c1662d374f63c2c0c96",
remote = "https://github.com/google/tcmalloc.git",
)

bazel_dep(name = "rules_bison", version = "0.2.2")
bazel_dep(name = "rules_flex", version = "0.2.1")
bazel_dep(name = "rules_m4", version = "0.2.3")
Expand Down
126 changes: 125 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion bazel/cc_toolchains/clang_cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,13 @@ def _impl(ctx):
target_system_name = identifier,
target_cpu = ctx.attr.target_cpu,

# This is used to expose a "flag" that `config_setting` rules can use to
# determine if the compiler is Clang.
compiler = "clang",

# These attributes aren't meaningful at all so just use placeholder
# values.
target_libc = "local",
compiler = "local",
abi_version = "local",
abi_libc_version = "local",

Expand Down

0 comments on commit eafff7e

Please sign in to comment.