From 5372bb344054135054205743c60a4c6b8646df8e Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 15 Dec 2025 16:04:34 +0100 Subject: [PATCH] [ty] Use jemalloc on linux (#21975) Co-authored-by: Claude --- Cargo.lock | 1 + crates/ty/Cargo.toml | 6 ++++++ crates/ty/src/main.rs | 16 ++++++++++++++++ scripts/ty_benchmark/src/benchmark/run.py | 7 ++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 9c5a084a58..cda8a8261d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4390,6 +4390,7 @@ dependencies = [ "ruff_python_trivia", "salsa", "tempfile", + "tikv-jemallocator", "toml", "tracing", "tracing-flame", diff --git a/crates/ty/Cargo.toml b/crates/ty/Cargo.toml index 4189758bb1..53a5bb7b15 100644 --- a/crates/ty/Cargo.toml +++ b/crates/ty/Cargo.toml @@ -51,5 +51,11 @@ regex = { workspace = true } tempfile = { workspace = true } toml = { workspace = true } +[features] +default = [] + +[target.'cfg(all(not(target_os = "macos"), not(target_os = "windows"), not(target_os = "openbsd"), not(target_os = "aix"), not(target_os = "android"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64", target_arch = "riscv64")))'.dependencies] +tikv-jemallocator = { workspace = true } + [lints] workspace = true diff --git a/crates/ty/src/main.rs b/crates/ty/src/main.rs index 6dbae583fe..102ec184e3 100644 --- a/crates/ty/src/main.rs +++ b/crates/ty/src/main.rs @@ -2,6 +2,22 @@ use colored::Colorize; use std::io; use ty::{ExitStatus, run}; +#[cfg(all( + not(target_os = "macos"), + not(target_os = "windows"), + not(target_os = "openbsd"), + not(target_os = "aix"), + not(target_os = "android"), + any( + target_arch = "x86_64", + target_arch = "aarch64", + target_arch = "powerpc64", + target_arch = "riscv64" + ) +))] +#[global_allocator] +static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + pub fn main() -> ExitStatus { run().unwrap_or_else(|error| { use io::Write; diff --git a/scripts/ty_benchmark/src/benchmark/run.py b/scripts/ty_benchmark/src/benchmark/run.py index 10e412dcd8..0c0cb34791 100644 --- a/scripts/ty_benchmark/src/benchmark/run.py +++ b/scripts/ty_benchmark/src/benchmark/run.py @@ -56,6 +56,7 @@ def main() -> None: parser.add_argument( "--ty-path", + action="append", type=Path, help="Path to the ty binary to benchmark.", ) @@ -108,7 +109,11 @@ def main() -> None: for tool_name in args.tool or TOOL_CHOICES: match tool_name: case "ty": - suites.append(Ty(path=args.ty_path)) + if args.ty_path: + for path in args.ty_path: + suites.append(Ty(path=path)) + else: + suites.append(Ty()) case "pyrefly": suites.append(Pyrefly()) case "pyright":