Skip to content

Switch Rust global allocator to tcmalloc. - #5344

Merged
graydon merged 1 commit into
stellar:masterfrom
dmkozh:rs_tcmalloc
Jul 24, 2026
Merged

Switch Rust global allocator to tcmalloc.#5344
graydon merged 1 commit into
stellar:masterfrom
dmkozh:rs_tcmalloc

Conversation

@dmkozh

@dmkozh dmkozh commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Switch Rust global allocator to tcmalloc.

tcmalloc yielded performance improvements for C++, and it's also significantly better than the system allocator on the apply time benchmarks (~30-50ms of apply time savings on large TPL benchmarks, like 6000 SAC TPS).

Rust implementation relies on the tcmalloc functions already linked into the Core binary. That's why we're using a custom allocator implementation instead of using an existing tcmalloc wrapper for Rust.

Checklist

  • Reviewed the contributing document
  • Rebased on top of master (no merge commits)
  • Ran clang-format v8.0.0 (via make format or the Visual Studio extension)
  • Compiles
  • Ran all tests
  • If change impacts performance, include supporting evidence per the performance document

Copilot AI review requested due to automatic review settings July 13, 2026 19:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR switches the Rust crate’s global allocator to use the C++-linked tcmalloc (gperftools) allocator when the build is configured with USE_TCMALLOC, aiming to improve performance by routing Rust (and embedded Soroban host) allocations through tcmalloc.

Changes:

  • Added a Rust GlobalAlloc implementation (TcMalloc) that forwards allocations to tc_* symbols provided by libtcmalloc_minimal.a.
  • Enabled the allocator via a new Cargo feature (tcmalloc) and a #[global_allocator] in the top-level Rust crate.
  • Updated the autotools build (src/Makefile.am) to pass --features tcmalloc to the Rust build whenever USE_TCMALLOC is set.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/rust/src/tcmalloc.rs Introduces a tcmalloc-backed Rust GlobalAlloc implementation.
src/rust/src/lib.rs Enables TcMalloc as the Rust global allocator under the tcmalloc feature.
src/rust/Cargo.toml Adds the tcmalloc feature flag for the Rust crate.
src/Makefile.am Wires USE_TCMALLOC to --features tcmalloc during Rust build invocations.

Comment thread src/rust/src/tcmalloc.rs
Comment thread src/rust/src/tcmalloc.rs

@graydon graydon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@graydon
graydon added this pull request to the merge queue Jul 22, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@graydon
graydon added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@dmkozh
dmkozh added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@dmkozh
dmkozh added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@dmkozh dmkozh closed this Jul 23, 2026
@dmkozh dmkozh reopened this Jul 23, 2026
@dmkozh
dmkozh enabled auto-merge July 23, 2026 18:05
tcmalloc yielded performance improvements for C++, and it's also significantly better than the system allocator on the apply time benchmarks (~30-50ms of apply time savings on large TPL benchmarks, like 6000 SAC TPS).
@dmkozh
dmkozh added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@dmkozh
dmkozh added this pull request to the merge queue Jul 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 23, 2026
@dmkozh
dmkozh added this pull request to the merge queue Jul 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 24, 2026
@graydon
graydon added this pull request to the merge queue Jul 24, 2026
Merged via the queue into stellar:master with commit c520557 Jul 24, 2026
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants