perf(ast, codegen, transformer): avoid allocations when converting RegExpFlags to string#9550
Merged
graphite-app[bot] merged 1 commit intomainfrom Mar 5, 2025
Conversation
This was referenced Mar 4, 2025
Member
Author
CodSpeed Performance ReportMerging #9550 will create unknown performance changesComparing Summary
Benchmarks breakdown
|
This was referenced Mar 4, 2025
camchenry
approved these changes
Mar 5, 2025
Member
|
I think the additional dependency is okay personally. It's not too surprising to me that the AST depends on data structures, especially custom ones. We can always turn them into separate crates (or features like you say) later. |
Contributor
Merge activity
|
…egExpFlags` to string (#9550) In various places, we were using `RegExpFlags::to_string` when we want a `&str`. This creates a `String` temporarily, which is an unnecessary allocation. Add `RegExpFlags::to_inline_string` method which creates an `InlineString` instead, without any allocation. Use this method wherever we convert from `RegExpFlags` to `&str`. The downside of this change is that `oxc_ast` gains a dependency on `oxc_data_structures`. Personally, I don't think this is so bad, as `oxc_data_structures` is a pretty lightweight crate, containing only quite minimalist data structures. The code is mostly comments! However, what we could do is put each component of `oxc_data_structures` behind it's own feature, so consumers can take only what they need.
b28aa93 to
29041fb
Compare
293598d to
6b4a8c6
Compare
Base automatically changed from
03-04-feat_data_structures_move_inlinestring_into_oxc_data_structures_crate
to
main
March 5, 2025 02:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

In various places, we were using
RegExpFlags::to_stringwhen we want a&str. This creates aStringtemporarily, which is an unnecessary allocation.Add
RegExpFlags::to_inline_stringmethod which creates anInlineStringinstead, without any allocation. Use this method wherever we convert fromRegExpFlagsto&str.The downside of this change is that
oxc_astgains a dependency onoxc_data_structures. Personally, I don't think this is so bad, asoxc_data_structuresis a pretty lightweight crate, containing only quite minimalist data structures. The code is mostly comments! However, what we could do is put each component ofoxc_data_structuresbehind it's own feature, so consumers can take only what they need.