From 4215159afc1597f43406a19adf73c61ba0cc4023 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 1 Jul 2026 11:40:52 +0000 Subject: [PATCH 1/3] Inline formatter printing hot paths --- crates/ruff_formatter/src/printer/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index e688b2069ecbb..d8dad1095c393 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -88,6 +88,9 @@ impl<'a> Printer<'a> { } /// Prints a single element and push the following elements to queue + // LLVM considers this function too large to inline on its own, but it is called for every + // element visited by the printing loop. + #[inline(always)] fn print_element( &mut self, stack: &mut PrintCallStack, @@ -438,6 +441,9 @@ impl<'a> Printer<'a> { Ok(print_mode) } + // LLVM considers this function too large to inline on its own, but it is called for every + // text element visited by the printing loop. + #[inline(always)] fn print_text(&mut self, text: Text) { if !self.state.pending_indent.is_empty() { let indent = std::mem::take(&mut self.state.pending_indent); From f0e998d5466f48f9907377b0ee8c965196983cc9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 1 Jul 2026 12:40:34 +0000 Subject: [PATCH 2/3] Fix inline-always Clippy lint --- crates/ruff_formatter/src/printer/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index d8dad1095c393..2146839763a23 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -443,6 +443,10 @@ impl<'a> Printer<'a> { // LLVM considers this function too large to inline on its own, but it is called for every // text element visited by the printing loop. + #[expect( + clippy::inline_always, + reason = "improves formatter benchmarks by 5-7%" + )] #[inline(always)] fn print_text(&mut self, text: Text) { if !self.state.pending_indent.is_empty() { From 1521be25947549931ea134b38bbed16b5ea92407 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 1 Jul 2026 12:42:27 +0000 Subject: [PATCH 3/3] Omit inline-always expect reason --- crates/ruff_formatter/src/printer/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/ruff_formatter/src/printer/mod.rs b/crates/ruff_formatter/src/printer/mod.rs index 2146839763a23..19ba2b84fd173 100644 --- a/crates/ruff_formatter/src/printer/mod.rs +++ b/crates/ruff_formatter/src/printer/mod.rs @@ -443,10 +443,7 @@ impl<'a> Printer<'a> { // LLVM considers this function too large to inline on its own, but it is called for every // text element visited by the printing loop. - #[expect( - clippy::inline_always, - reason = "improves formatter benchmarks by 5-7%" - )] + #[expect(clippy::inline_always)] #[inline(always)] fn print_text(&mut self, text: Text) { if !self.state.pending_indent.is_empty() {