Skip to content

Commit 3f53b6f

Browse files
committed
refactor(ast): make AST structs repr(C). (#4614)
Make structs `#[repr(C)]` without reordering them to benchmark the performance implications of it. This PR adds 136 bytes of padding in total. You can visit the list of these types [here](https://github.com/oxc-project/oxc/pull/4404/files/)(checkout the `assert_layouts.rs` diff). Update: Doesn't seem too bad! ![image](https://github.com/user-attachments/assets/05ac9cc8-7cb0-4ed5-9220-44f65c7f5bb9) * Linter: We can easily get more than 1% performance gain in the linter to even things out * Prepass: If we fix our issue with Rust `1.80.0` we gain 13% And it should also be possible to find some other areas there to gain back this one percent. The most notable thing is that `parser` isn't impacted by this, That is our most optimized crate which every percent counts(and it can be hard to gain back any perf regression there).
1 parent bcfa297 commit 3f53b6f

File tree

1 file changed

+3
-3
lines changed
  • crates/oxc_ast_macros/src

1 file changed

+3
-3
lines changed

crates/oxc_ast_macros/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ fn enum_repr(enum_: &syn::ItemEnum) -> TokenStream2 {
1717
/// It is also a lightweight macro; All of its computation is cached and
1818
/// it only applies the following changes without any complex operation:
1919
///
20+
/// * Prepend `#[repr(C)]` to structs
2021
/// * Prepend `#[repr(C, u8)]` to fieldful enums e.g. `enum E { X: u32, Y: u8 }`
2122
/// * Prepend `#[repr(u8)]` to unit (fieldless) enums e.g. `enum E { X, Y, Z, }`
22-
/// * Prepend `#[derive(oxc_ast_macros::Ast)]`
23+
/// * Prepend `#[derive(oxc_ast_macros::Ast)]` to all structs and enums
2324
///
2425
#[proc_macro_attribute]
2526
#[allow(clippy::missing_panics_doc)]
@@ -28,8 +29,7 @@ pub fn ast(_args: TokenStream, input: TokenStream) -> TokenStream {
2829

2930
let repr = match input {
3031
syn::Item::Enum(ref enum_) => enum_repr(enum_),
31-
// In future, we'll add `#[repr(C)]` to structs, but at present this is disabled
32-
syn::Item::Struct(_) => TokenStream2::default(),
32+
syn::Item::Struct(_) => quote!(#[repr(C)]),
3333

3434
_ => {
3535
unreachable!()

0 commit comments

Comments
 (0)