From b736a1f92bbbeb8c7cdd4e4d79472f4ce666dbac Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Wed, 14 Oct 2026 16:40:04 +0900 Subject: [PATCH] Increase LLVM inline-threshold to 5000 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compared to the default of 225, this gives noticeable performance improvements. For the following benchmark: objs = [] 2_000_000.times { objs << Object.new } We can see this branch is about 10% faster: Benchmark 1: branch Time (mean ± σ): 193.0 ms ± 3.3 ms [User: 207.0 ms, System: 79.2 ms] Range (min … max): 189.1 ms … 203.1 ms 15 runs Benchmark 2: master Time (mean ± σ): 214.9 ms ± 4.9 ms [User: 245.2 ms, System: 79.5 ms] Range (min … max): 206.4 ms … 220.4 ms 13 runs Summary branch ran 1.11 ± 0.03 times faster than master --- gc/mmtk/depend | 14 +++++++++++++- gc/mmtk/extconf.rb | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gc/mmtk/depend b/gc/mmtk/depend index 1689f9d..79f9200 100644 --- a/gc/mmtk/depend +++ b/gc/mmtk/depend @@ -2,10 +2,22 @@ $(TARGET_SO): $(MMTK_BUILD)/$(LIBMMTK_RUBY) $(OBJS): Makefile +# A raised LLVM inline threshold for the Rust GC code: this is what fuses the +# per-object marking pipeline (work packet loop, closure trampoline, type fast +# paths, mark enqueue) into straight-line code. Without it the fast paths in +# scanning.rs stay behind real calls and the win evaporates. +# +# The flag must reach rustc either via the target-scoped RUSTFLAGS in +# MMTK_CARGO_ENV (LTO builds, see extconf.rb) or via plain RUSTFLAGS. Never +# set both: plain RUSTFLAGS has higher precedence in Cargo and would clobber +# the target-scoped flags. +MMTK_INLINE_THRESHOLD = 5000 +MMTK_THRESHOLD_RUSTFLAGS = -Cllvm-args=-inline-threshold=$(MMTK_INLINE_THRESHOLD) + release/$(LIBMMTK_RUBY) debug/$(LIBMMTK_RUBY): $(RUSTSRCS) $(srcdir)/Cargo.toml $(srcdir)/Cargo.lock Makefile release/$(LIBMMTK_RUBY): - CARGO_TARGET_DIR="." $(MMTK_CARGO_ENV) cargo build --manifest-path=$(srcdir)/Cargo.toml --release $(MMTK_CARGO_FLAGS) + CARGO_TARGET_DIR="." $(if $(MMTK_CARGO_ENV),,RUSTFLAGS="$(RUSTFLAGS) $(MMTK_THRESHOLD_RUSTFLAGS)") $(MMTK_CARGO_ENV) cargo build --manifest-path=$(srcdir)/Cargo.toml --release $(MMTK_CARGO_FLAGS) $(MMTK_CARGO_FIXUP) debug/$(LIBMMTK_RUBY): diff --git a/gc/mmtk/extconf.rb b/gc/mmtk/extconf.rb index 70244ae..3674204 100644 --- a/gc/mmtk/extconf.rb +++ b/gc/mmtk/extconf.rb @@ -134,7 +134,7 @@ def filter_warnflags(cc, flags) CFLAGS += #{cflags} DLDFLAGS += #{ldflags} warnflags = #{warnflags} - MMTK_CARGO_ENV = #{env}="-Clinker-plugin-lto -C target-cpu=native" + MMTK_CARGO_ENV = #{env}="-Clinker-plugin-lto -C target-cpu=native -Cllvm-args=-inline-threshold=$(MMTK_INLINE_THRESHOLD)" MMTK_CARGO_FLAGS = --target #{lto[:host]} MMTK_CARGO_FIXUP = mkdir -p release && cp -f #{lto[:host]}/release/$(LIBMMTK_RUBY) release/$(LIBMMTK_RUBY) endif