From afc4548ef4bc0f7dd0b32f27740325965d6c27c8 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:17:29 +0000 Subject: [PATCH] perf(ast)!: educe byte size of `TaggedTemplateExpression::quasi` by `Boxing` it (#5679) --- crates/oxc_ast/src/ast/js.rs | 2 +- .../oxc_ast/src/generated/assert_layouts.rs | 8 ++--- crates/oxc_ast/src/generated/ast_builder.rs | 29 ++++++++++--------- crates/oxc_traverse/src/generated/ancestor.rs | 8 ++--- crates/oxc_traverse/src/generated/walk.rs | 4 +-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index cca85e2b9..862361ef8 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -461,7 +461,7 @@ pub struct TaggedTemplateExpression<'a> { #[serde(flatten)] pub span: Span, pub tag: Expression<'a>, - pub quasi: TemplateLiteral<'a>, + pub quasi: Box<'a, TemplateLiteral<'a>>, pub type_parameters: Option>>, } diff --git a/crates/oxc_ast/src/generated/assert_layouts.rs b/crates/oxc_ast/src/generated/assert_layouts.rs index 049f15187..a5efa0cd7 100644 --- a/crates/oxc_ast/src/generated/assert_layouts.rs +++ b/crates/oxc_ast/src/generated/assert_layouts.rs @@ -138,12 +138,12 @@ const _: () = { assert!(offset_of!(TemplateLiteral, quasis) == 8usize); assert!(offset_of!(TemplateLiteral, expressions) == 40usize); - assert!(size_of::() == 104usize); + assert!(size_of::() == 40usize); assert!(align_of::() == 8usize); assert!(offset_of!(TaggedTemplateExpression, span) == 0usize); assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize); assert!(offset_of!(TaggedTemplateExpression, quasi) == 24usize); - assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 96usize); + assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 32usize); assert!(size_of::() == 48usize); assert!(align_of::() == 8usize); @@ -1693,12 +1693,12 @@ const _: () = { assert!(offset_of!(TemplateLiteral, quasis) == 8usize); assert!(offset_of!(TemplateLiteral, expressions) == 24usize); - assert!(size_of::() == 60usize); + assert!(size_of::() == 24usize); assert!(align_of::() == 4usize); assert!(offset_of!(TaggedTemplateExpression, span) == 0usize); assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize); assert!(offset_of!(TaggedTemplateExpression, quasi) == 16usize); - assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 56usize); + assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 20usize); assert!(size_of::() == 28usize); assert!(align_of::() == 4usize); diff --git a/crates/oxc_ast/src/generated/ast_builder.rs b/crates/oxc_ast/src/generated/ast_builder.rs index e159f7db0..4f46f8fcb 100644 --- a/crates/oxc_ast/src/generated/ast_builder.rs +++ b/crates/oxc_ast/src/generated/ast_builder.rs @@ -1075,15 +1075,16 @@ impl<'a> AstBuilder<'a> { /// - quasi /// - type_parameters #[inline] - pub fn expression_tagged_template( + pub fn expression_tagged_template( self, span: Span, tag: Expression<'a>, - quasi: TemplateLiteral<'a>, - type_parameters: T1, + quasi: T1, + type_parameters: T2, ) -> Expression<'a> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>, + T2: IntoIn<'a, Option>>>, { Expression::TaggedTemplateExpression(self.alloc(self.tagged_template_expression( span, @@ -1989,20 +1990,21 @@ impl<'a> AstBuilder<'a> { /// - quasi /// - type_parameters #[inline] - pub fn tagged_template_expression( + pub fn tagged_template_expression( self, span: Span, tag: Expression<'a>, - quasi: TemplateLiteral<'a>, - type_parameters: T1, + quasi: T1, + type_parameters: T2, ) -> TaggedTemplateExpression<'a> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>, + T2: IntoIn<'a, Option>>>, { TaggedTemplateExpression { span, tag, - quasi, + quasi: quasi.into_in(self.allocator), type_parameters: type_parameters.into_in(self.allocator), } } @@ -2017,15 +2019,16 @@ impl<'a> AstBuilder<'a> { /// - quasi /// - type_parameters #[inline] - pub fn alloc_tagged_template_expression( + pub fn alloc_tagged_template_expression( self, span: Span, tag: Expression<'a>, - quasi: TemplateLiteral<'a>, - type_parameters: T1, + quasi: T1, + type_parameters: T2, ) -> Box<'a, TaggedTemplateExpression<'a>> where - T1: IntoIn<'a, Option>>>, + T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>, + T2: IntoIn<'a, Option>>>, { Box::new_in( self.tagged_template_expression(span, tag, quasi, type_parameters), diff --git a/crates/oxc_traverse/src/generated/ancestor.rs b/crates/oxc_traverse/src/generated/ancestor.rs index 0dbe693eb..e9ea50f8f 100644 --- a/crates/oxc_traverse/src/generated/ancestor.rs +++ b/crates/oxc_traverse/src/generated/ancestor.rs @@ -2612,10 +2612,10 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTag<'a, 't> { } #[inline] - pub fn quasi(self) -> &'t TemplateLiteral<'a> { + pub fn quasi(self) -> &'t Box<'a, TemplateLiteral<'a>> { unsafe { &*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI) - as *const TemplateLiteral<'a>) + as *const Box<'a, TemplateLiteral<'a>>) } } @@ -2684,10 +2684,10 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTypeParameters<'a, 't> { } #[inline] - pub fn quasi(self) -> &'t TemplateLiteral<'a> { + pub fn quasi(self) -> &'t Box<'a, TemplateLiteral<'a>> { unsafe { &*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI) - as *const TemplateLiteral<'a>) + as *const Box<'a, TemplateLiteral<'a>>) } } } diff --git a/crates/oxc_traverse/src/generated/walk.rs b/crates/oxc_traverse/src/generated/walk.rs index 775af069f..c186d0fa3 100644 --- a/crates/oxc_traverse/src/generated/walk.rs +++ b/crates/oxc_traverse/src/generated/walk.rs @@ -486,8 +486,8 @@ pub(crate) unsafe fn walk_tagged_template_expression<'a, Tr: Traverse<'a>>( ctx.retag_stack(AncestorType::TaggedTemplateExpressionQuasi); walk_template_literal( traverser, - (node as *mut u8).add(ancestor::OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI) - as *mut TemplateLiteral, + (&mut **((node as *mut u8).add(ancestor::OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI) + as *mut Box)) as *mut _, ctx, ); if let Some(field) = &mut *((node as *mut u8)