Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(ast)!: reduce byte size of TSImportType::attributes by Boxing it #5678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ pub struct TSImportType<'a> {
pub is_type_of: bool, // `typeof import("foo")`
pub parameter: TSType<'a>,
pub qualifier: Option<TSTypeName<'a>>,
pub attributes: Option<TSImportAttributes<'a>>,
pub attributes: Option<Box<'a, TSImportAttributes<'a>>>,
pub type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
}

Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,14 +1134,14 @@ const _: () = {
assert!(size_of::<TSTypeQueryExprName>() == 16usize);
assert!(align_of::<TSTypeQueryExprName>() == 8usize);

assert!(size_of::<TSImportType>() == 120usize);
assert!(size_of::<TSImportType>() == 64usize);
assert!(align_of::<TSImportType>() == 8usize);
assert!(offset_of!(TSImportType, span) == 0usize);
assert!(offset_of!(TSImportType, is_type_of) == 8usize);
assert!(offset_of!(TSImportType, parameter) == 16usize);
assert!(offset_of!(TSImportType, qualifier) == 32usize);
assert!(offset_of!(TSImportType, attributes) == 48usize);
assert!(offset_of!(TSImportType, type_parameters) == 112usize);
assert!(offset_of!(TSImportType, type_parameters) == 56usize);

assert!(size_of::<TSImportAttributes>() == 64usize);
assert!(align_of::<TSImportAttributes>() == 8usize);
Expand Down Expand Up @@ -2689,14 +2689,14 @@ const _: () = {
assert!(size_of::<TSTypeQueryExprName>() == 8usize);
assert!(align_of::<TSTypeQueryExprName>() == 4usize);

assert!(size_of::<TSImportType>() == 72usize);
assert!(size_of::<TSImportType>() == 36usize);
assert!(align_of::<TSImportType>() == 4usize);
assert!(offset_of!(TSImportType, span) == 0usize);
assert!(offset_of!(TSImportType, is_type_of) == 8usize);
assert!(offset_of!(TSImportType, parameter) == 12usize);
assert!(offset_of!(TSImportType, qualifier) == 20usize);
assert!(offset_of!(TSImportType, attributes) == 28usize);
assert!(offset_of!(TSImportType, type_parameters) == 68usize);
assert!(offset_of!(TSImportType, type_parameters) == 32usize);

assert!(size_of::<TSImportAttributes>() == 40usize);
assert!(align_of::<TSImportAttributes>() == 4usize);
Expand Down
38 changes: 21 additions & 17 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8845,17 +8845,18 @@ impl<'a> AstBuilder<'a> {
/// - attributes
/// - type_parameters
#[inline]
pub fn ts_type_import_type<T1>(
pub fn ts_type_import_type<T1, T2>(
self,
span: Span,
is_type_of: bool,
parameter: TSType<'a>,
qualifier: Option<TSTypeName<'a>>,
attributes: Option<TSImportAttributes<'a>>,
type_parameters: T1,
attributes: T1,
type_parameters: T2,
) -> TSType<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
TSType::TSImportType(self.alloc(self.ts_import_type(
span,
Expand Down Expand Up @@ -11696,17 +11697,18 @@ impl<'a> AstBuilder<'a> {
/// - attributes
/// - type_parameters
#[inline]
pub fn ts_type_query_expr_name_import_type<T1>(
pub fn ts_type_query_expr_name_import_type<T1, T2>(
self,
span: Span,
is_type_of: bool,
parameter: TSType<'a>,
qualifier: Option<TSTypeName<'a>>,
attributes: Option<TSImportAttributes<'a>>,
type_parameters: T1,
attributes: T1,
type_parameters: T2,
) -> TSTypeQueryExprName<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
TSTypeQueryExprName::TSImportType(self.alloc(self.ts_import_type(
span,
Expand Down Expand Up @@ -11747,24 +11749,25 @@ impl<'a> AstBuilder<'a> {
/// - attributes
/// - type_parameters
#[inline]
pub fn ts_import_type<T1>(
pub fn ts_import_type<T1, T2>(
self,
span: Span,
is_type_of: bool,
parameter: TSType<'a>,
qualifier: Option<TSTypeName<'a>>,
attributes: Option<TSImportAttributes<'a>>,
type_parameters: T1,
attributes: T1,
type_parameters: T2,
) -> TSImportType<'a>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
TSImportType {
span,
is_type_of,
parameter,
qualifier,
attributes,
attributes: attributes.into_in(self.allocator),
type_parameters: type_parameters.into_in(self.allocator),
}
}
Expand All @@ -11781,17 +11784,18 @@ impl<'a> AstBuilder<'a> {
/// - attributes
/// - type_parameters
#[inline]
pub fn alloc_ts_import_type<T1>(
pub fn alloc_ts_import_type<T1, T2>(
self,
span: Span,
is_type_of: bool,
parameter: TSType<'a>,
qualifier: Option<TSTypeName<'a>>,
attributes: Option<TSImportAttributes<'a>>,
type_parameters: T1,
attributes: T1,
type_parameters: T2,
) -> Box<'a, TSImportType<'a>>
where
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSImportAttributes<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
{
Box::new_in(
self.ts_import_type(
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_traverse/src/generated/ancestor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11914,10 +11914,10 @@ impl<'a, 't> TSImportTypeWithoutParameter<'a, 't> {
}

#[inline]
pub fn attributes(self) -> &'t Option<TSImportAttributes<'a>> {
pub fn attributes(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_ATTRIBUTES)
as *const Option<TSImportAttributes<'a>>)
as *const Option<Box<'a, TSImportAttributes<'a>>>)
}
}

Expand Down Expand Up @@ -11956,10 +11956,10 @@ impl<'a, 't> TSImportTypeWithoutQualifier<'a, 't> {
}

#[inline]
pub fn attributes(self) -> &'t Option<TSImportAttributes<'a>> {
pub fn attributes(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_ATTRIBUTES)
as *const Option<TSImportAttributes<'a>>)
as *const Option<Box<'a, TSImportAttributes<'a>>>)
}
}

Expand Down Expand Up @@ -12048,10 +12048,10 @@ impl<'a, 't> TSImportTypeWithoutTypeParameters<'a, 't> {
}

#[inline]
pub fn attributes(self) -> &'t Option<TSImportAttributes<'a>> {
pub fn attributes(self) -> &'t Option<Box<'a, TSImportAttributes<'a>>> {
unsafe {
&*((self.0 as *const u8).add(OFFSET_TS_IMPORT_TYPE_ATTRIBUTES)
as *const Option<TSImportAttributes<'a>>)
as *const Option<Box<'a, TSImportAttributes<'a>>>)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_traverse/src/generated/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5139,10 +5139,10 @@ pub(crate) unsafe fn walk_ts_import_type<'a, Tr: Traverse<'a>>(
walk_ts_type_name(traverser, field as *mut _, ctx);
}
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_TS_IMPORT_TYPE_ATTRIBUTES)
as *mut Option<TSImportAttributes>)
as *mut Option<Box<TSImportAttributes>>)
{
ctx.retag_stack(AncestorType::TSImportTypeAttributes);
walk_ts_import_attributes(traverser, field as *mut _, ctx);
walk_ts_import_attributes(traverser, (&mut **field) as *mut _, ctx);
}
if let Some(field) = &mut *((node as *mut u8)
.add(ancestor::OFFSET_TS_IMPORT_TYPE_TYPE_PARAMETERS)
Expand Down