oxc icon indicating copy to clipboard operation
oxc copied to clipboard

feat(ast_tools): pre-compile `#[ast]` macro output

Open overlookmotel opened this issue 1 year ago • 3 comments

Work in progress.

Generate code for #[ast] macro with an oxc_ast_tools generator.

oxc_ast_macros crate now has no dependencies (no syn etc).

The guts of it is the code! macro. This is the same as quote!, except it evaluates to a TokenStream of code to create the TokenStream which quote! evaluates to.

Unfortunately I'm not seeing an improvement in compile times, because other dependencies of oxc_ast also use syn, so it doesn't drop from the dependency graph. ~~The generated code is 3000 lines, and could likely be shrunk down, which also could help.~~ The generated code is now 600 lines, and now there is a 5% reduction in debug build time for oxc_ast crate - but that's still a disappointingly small improvement.

Am opening this PR not necessarily with the intent of merging it, but to discuss whether this is maybe a useful approach. @rzvxa would appreciate your feedback.

Note: This technique would allow #[generate_derive] to inject the derived impl next to the type def, same as #[derive] does, which would solve the problem of types/fields needing to be pub(crate).

overlookmotel avatar Sep 15 '24 23:09 overlookmotel

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

graphite-app[bot] avatar Sep 15 '24 23:09 graphite-app[bot]

  • #5796 Graphite 👈
  • #5793 Graphite
  • #5792 Graphite
  • #5791 Graphite
  • main

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @overlookmotel and the rest of your teammates on Graphite Graphite

overlookmotel avatar Sep 15 '24 23:09 overlookmotel

CodSpeed Performance Report

Merging oxc-project/oxc#5796 will not alter performance

Comparing 09-14-feat_ast_tools_pre-compile_ast_macro_output (90746ab) with main (bb95306)

Summary

✅ 29 untouched benchmarks

codspeed-hq[bot] avatar Sep 15 '24 23:09 codspeed-hq[bot]

Close as stale. Feel free to revive this.

Boshen avatar Nov 26 '24 15:11 Boshen

Archived on overlookmotel/precompile-ast-macro-output branch.

overlookmotel avatar Nov 26 '24 15:11 overlookmotel