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

This commit is contained in:
Boshen 2024-09-10 14:07:51 +00:00
parent ee4fb42d70
commit 7415e85764
5 changed files with 34 additions and 30 deletions

View file

@ -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>>>,
}

View file

@ -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);
@ -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);

View file

@ -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,
@ -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,
@ -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),
}
}
@ -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(

View file

@ -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>>>)
}
}
@ -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>>>)
}
}
@ -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>>>)
}
}
}

View file

@ -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)