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

Store Semantic data in arena #31

Open
overlookmotel opened this issue Jun 4, 2024 · 1 comment
Open

Store Semantic data in arena #31

overlookmotel opened this issue Jun 4, 2024 · 1 comment

Comments

@overlookmotel
Copy link

overlookmotel commented Jun 4, 2024

Semantic's data structures seem like a good candidate for arena allocation - lots of small structures built in a short space of time and then dropped simultaneously (much like the AST itself).

Semantic<'a> already has a lifetime, so moving the data into arena would not affect ergonomics of API.

The one downside of the arena allocator is that Vecs never grow in place, they always reallocate and are copied when they grow beyond capacity, because bumpalo packs data tightly and grows downwards.

This problem could be largely ameliorated if:

  • Parser counts number of scopes, symbols and references during parsing.
  • Initialize ScopeTree's Vecs with required capacity at the start, so they never need to grow.

Additional benefits:

  • Storing semantic data in arena makes it available in JS via AST transfer (for building e.g. linter rules / transform plugins in JS).
  • Ditto for Deserializable ast nodes oxc#3079 (if we want to do that)
@overlookmotel
Copy link
Author

We should probably store Semantic in a separate arena from AST itself, so AST remains compact in memory.

oxc_allocator::Allocator could contain both arenas:

struct Allocator {
  ast_arena: bumpalo::Bump,
  semantic_arena: bumpalo::Bump,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant