Skip to content

Commit

Permalink
Directly use TCMalloc rather than the system malloc on Linux.
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

This is also only enabled on Linux as there is no support for other OSes
at the moment.
  • Loading branch information
chandlerc committed Jul 15, 2024
1 parent 2fcff24 commit e41f730
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 @@ -110,6 +110,9 @@ build --action_env=LANG=en_US.UTF-8
build --enable_platform_specific_config
build:linux --define=pfm=1

# Enable TCMalloc on Linux as well.
build:linux --custom_malloc=@tcmalloc//tcmalloc

# Allow users to override any of the flags desired by importing a user-specific
# RC file here if present.
try-import %workspace%/user.bazelrc
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 e41f730

Please sign in to comment.