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

perf(semantic): allocate symbol data in Allocator #8012

Merged

Conversation

Boshen
Copy link
Member

@Boshen Boshen commented Dec 19, 2024

No description provided.

@Boshen Boshen requested a review from Dunqing as a code owner December 19, 2024 06:39
@github-actions github-actions bot added A-semantic Area - Semantic C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Dec 19, 2024
Copy link
Member Author

Boshen commented Dec 19, 2024


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch from 7dcb30b to e2dce26 Compare December 19, 2024 06:44
@Boshen Boshen marked this pull request as draft December 19, 2024 06:47
@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch 2 times, most recently from b86d84c to b12bcfd Compare December 19, 2024 06:56
Copy link

codspeed-hq bot commented Dec 19, 2024

CodSpeed Performance Report

Merging #8012 will improve performances by 4.95%

Comparing 12-19-refactor_semantic_allocate_data_in_allocator (414e828) with main (8547e02)

Summary

⚡ 3 improvements
✅ 26 untouched benchmarks

Benchmarks breakdown

Benchmark main 12-19-refactor_semantic_allocate_data_in_allocator Change
semantic[antd.js] 111.4 ms 106.2 ms +4.95%
semantic[checker.ts] 67.5 ms 65.3 ms +3.42%
semantic[pdf.mjs] 18.2 ms 17.5 ms +4.44%

@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch from be398ef to 556c1da Compare December 19, 2024 08:31
@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch from 556c1da to 9c1d58d Compare December 20, 2024 03:14
@Boshen Boshen changed the title refactor(semantic): allocate data in Allocator refactor(semantic): allocate symbol data in Allocator Dec 20, 2024
@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch 2 times, most recently from 2bd9e14 to 0864eb2 Compare December 20, 2024 13:55
@Boshen Boshen marked this pull request as ready for review December 20, 2024 13:55
@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch from 0864eb2 to 0f6ac92 Compare December 20, 2024 13:59
@Boshen Boshen changed the title refactor(semantic): allocate symbol data in Allocator perf(semantic): allocate symbol data in Allocator Dec 20, 2024
@github-actions github-actions bot added the C-performance Category - Solution not expected to change functional behavior, only performance label Dec 20, 2024
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Dec 20, 2024
Copy link
Member Author

Boshen commented Dec 20, 2024

Merge activity

  • Dec 20, 9:13 AM EST: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Dec 20, 9:13 AM EST: A user added this pull request to the Graphite merge queue.
  • Dec 20, 9:17 AM EST: A user merged this pull request with the Graphite merge queue.

@Boshen Boshen force-pushed the 12-19-refactor_semantic_allocate_data_in_allocator branch from 0f6ac92 to 414e828 Compare December 20, 2024 14:13
@graphite-app graphite-app bot merged commit 414e828 into main Dec 20, 2024
26 checks passed
@graphite-app graphite-app bot deleted the 12-19-refactor_semantic_allocate_data_in_allocator branch December 20, 2024 14:17
@overlookmotel
Copy link
Contributor

@Boshen I think implementing Send on Allocator is perfectly safe. bumpalo::Bump implements Send, if I remember correctly.

But implementing Sync is definitely not safe, and likely a footgun (aka recipe for disaster).

I imagine Send is all that Rolldown needs?

@Boshen
Copy link
Member Author

Boshen commented Dec 20, 2024

@Boshen I think implementing Send on Allocator is perfectly safe. bumpalo::Bump implements Send, if I remember correctly.

But implementing Sync is definitely not safe, and likely a footgun (aka recipe for disaster).

I imagine Send is all that Rolldown needs?

error[E0277]: `Cell<NonNull<bumpalo::ChunkFooter>>` cannot be shared between threads safely
   --> crates/rolldown_plugin/src/plugin_context.rs:127:13
    |
127 |       .await?;
    |             ^ `Cell<NonNull<bumpalo::ChunkFooter>>` cannot be shared between threads safely
    |
    = help: within `oxc_allocator::Allocator`, the trait `Sync` is not implemented for `Cell<NonNull<bumpalo::ChunkFooter>>`, which is required by `Result<(), anyhow::Error>: FromResidual<Result<Infallible, tokio::sync::mpsc::error::SendError<ModuleLoaderMsg>>>`
    = note: if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`
    = help: the trait `FromResidual<Result<Infallible, E>>` is implemented for `Result<T, F>`
note: required because it appears within the type `bumpalo::Bump`
   --> /Users/boshen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bumpalo-3.16.0/src/lib.rs:292:12
    |
292 | pub struct Bump {
    |            ^^^^
note: required because it appears within the type `oxc_allocator::Allocator`
   --> /Users/boshen/oxc/oxc/crates/oxc_allocator/src/lib.rs:71:12
    |
71  | pub struct Allocator {
    |            ^^^^^^^^^
    = note: required for `UnsafeSelfCell<SymbolTableCell, Allocator, SymbolTableInner<'static>>` to implement `Sync`
note: required because it appears within the type `oxc_semantic::symbol::SymbolTableCell`
   --> /Users/boshen/oxc/oxc/crates/oxc_semantic/src/symbol.rs:60:12
    |
60  |     struct SymbolTableCell {
    |            ^^^^^^^^^^^^^^^
note: required because it appears within the type `oxc_semantic::symbol::SymbolTable`
   --> /Users/boshen/oxc/oxc/crates/oxc_semantic/src/symbol.rs:21:12
    |
21  | pub struct SymbolTable {
    |            ^^^^^^^^^^^
note: required because it appears within the type `SymbolRefDbForModule`
   --> /Users/boshen/github/rolldown/crates/rolldown_common/src/types/symbol_ref_db.rs:37:12
    |
37  | pub struct SymbolRefDbForModule {
    |            ^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `RuntimeModuleTaskResult`
   --> /Users/boshen/github/rolldown/crates/rolldown_common/src/module_loader/runtime_task_result.rs:8:12
    |
8   | pub struct RuntimeModuleTaskResult {
    |            ^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `ModuleLoaderMsg`
   --> /Users/boshen/github/rolldown/crates/rolldown_common/src/module_loader/mod.rs:11:10
    |
11  | pub enum ModuleLoaderMsg {
    |          ^^^^^^^^^^^^^^^
note: required because it appears within the type `tokio::sync::mpsc::error::SendError<ModuleLoaderMsg>`
   --> /Users/boshen/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.42.0/src/sync/mpsc/error.rs:8:12
    |
8   | pub struct SendError<T>(pub T);
    |            ^^^^^^^^^
    = note: required for `anyhow::Error` to implement `From<tokio::sync::mpsc::error::SendError<ModuleLoaderMsg>>`
    = note: required for `Result<(), anyhow::Error>` to implement `FromResidual<Result<Infallible, tokio::sync::mpsc::error::SendError<ModuleLoaderMsg>>>`
    = note: the full name for the type has been written to '/Users/boshen/github/rolldown/target/debug/deps/rolldown_plugin-966d208a591aeead.long-type-4702483371421541226.txt'
    = note: consider using `--verbose` to print the full type name to the console

@overlookmotel
Copy link
Contributor

OK, well it's asking for trouble in my opinion! Bump is not thread-safe. You can move it from one thread to another no problem. But you can't safely share it between threads.

Boshen added a commit that referenced this pull request Dec 21, 2024
## [0.43.0] - 2024-12-21

- de4c772 traverse: [**BREAKING**] Rename `Ancestor::is_via_*` methods
to `is_parent_of_*` (#8031) (overlookmotel)

- ed75e42 semantic: [**BREAKING**] Make SymbolTable fields `pub(crate)`
instead of `pub` (#7999) (Boshen)

### Features

- 75b775c allocator: `Vec<u8>::into_string` (#8017) (overlookmotel)
- 8547e02 ast: Implement `allocator_api2` for `Allocator` (#8043)
(Boshen)
- 63a95e4 ast: Add `AstBulder::move_property_key` (#7998)
(overlookmotel)
- 897a1a8 transformer/class-properties: Exit faster from super
replacement visitor (#8028) (overlookmotel)
- 3ea4109 transformer/class-properties: Transform super update
expressions within static prop initializer (#7997) (Dunqing)
- cc57db3 transformer/class-properties: Transform super assignment
expressions within static prop initializer (#7991) (Dunqing)
- 6b6444b traverse: Record current block scope (#8007) (overlookmotel)

### Bug Fixes

- 043252d transformer/class-properties: Replace `this` and class name in
static blocks (#8035) (overlookmotel)
- 273795d transformer/class-properties: Run other transforms on static
properties, static blocks, and computed keys (#7982) (overlookmotel)

### Performance

- c0dd3f8 ast: `move_expression` and `move_statement` produce dummy with
no span (#7995) (overlookmotel)
- 862838f codegen: Remove useless to_owned (#8014) (Dunqing)
- 2736657 semantic: Allocate `UnresolvedReferences` in allocator (#8046)
(Boshen)
- 2e8872c semantic: Allocate child scope in allocator (#8045) (Boshen)
- 414e828 semantic: Allocate symbol data in Allocator (#8012) (Boshen)
- 7aebed0 semantic: Allocate `Bindings` in allocator (#8021) (Boshen)
- 0f9308f transformer/react-refresh: Reduce allocations (#8018)
(overlookmotel)
- 0deb9e6 transformer/react-refresh: Reserve capacity in hook key string
(#8016) (overlookmotel)
- 7b70347 transformer/react-refresh: Avoid allocating string in each
hook call (#8013) (Dunqing)

### Documentation

- df5c341 ast: Improve docs for `AstBuilder::move_*` methods (#7994)
(overlookmotel)

### Refactor

- f1adf9f semantic: `ScopeTree::rename_binding` remove old binding first
(#8020) (overlookmotel)
- 02f968d semantic: Change `Bindings` to a plain `FxHashMap` (#8019)
(Boshen)
- e7476a1 semantic: Remove `serialize` (#8015) (Boshen)
- 1cf7b83 semantic: Simplify handling namespace stack (#7987) (Dunqing)
- 48cb52b semantic: Remove resetting `current_reference_flags` in visit
functions (#7986) (Dunqing)
- 3250a47 semantic: Remove unused current_symbol_flags (#7985) (Dunqing)
- efe96ec semantic: Use `Stack` for function stack node ids (#7984)
(Dunqing)
- ac097e9 transformer/class-properties: Rename file (#8036)
(overlookmotel)
- 059a5dd transformer/class-properties: Do not pass `ScopeId` into
`insert_instance_inits` (#8001) (overlookmotel)
- 0a38eea transformer/class-properties: Use `temp_var_name_base` to
generate temp var names for `super` transform (#8004) (overlookmotel)
- d1b7181 transformer/class-properties: Rename var (#8006)
(overlookmotel)
- 5a23d72 transformer/class-properties: Remove outdated comment (#8000)
(overlookmotel)
- b3a5f3e transformer/class-properties: Mark
`transform_assignment_expression_if_super_member_assignment_target` as
inline (#7993) (Dunqing)

### Testing

- bcb33c0 semantic: Add a test for catch parameters reference (#7988)
(Dunqing)

Co-authored-by: Boshen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-semantic Area - Semantic C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior C-performance Category - Solution not expected to change functional behavior, only performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants