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(atoms): Introduce AtomStoreCell #8232

Merged
merged 5 commits into from
Nov 9, 2023

Conversation

dsherret
Copy link
Contributor

@dsherret dsherret commented Nov 7, 2023

Introduces an AtomStoreCell type which internally uses an UnsafeCell, but enforces a safe contract. This allows skipping the borrow check of RefCell.

> cargo "bench" "--package" "swc_ecma_parser" "--bench" "parser" "--" "three"

Main: ~37.8ms
This PR: ~37.4ms

Comment on lines 32 to 33
// SAFETY: We can skip the borrow check of RefCell because
// this API enforces a safe contract. It is slightly faster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment is wrong.
It's safe because of the way we use from the parser, not because of API.

Copy link
Contributor Author

@dsherret dsherret Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use the current API of AtomStoreCell in an unsafe way? (With respect to an UnsafeCell vs RefCell. I'm not sure what's going on internally in AtomStore and Atom)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you are right. The mutable borrow ends in the function.

Can you add this to the comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will do it in the morning here.

@kdy1
Copy link
Member

kdy1 commented Nov 7, 2023

Maybe we can move this to swc_atoms

@kdy1 kdy1 requested review from magic-akari, Austaras and kdy1 November 7, 2023 08:51
@dsherret dsherret marked this pull request as ready for review November 7, 2023 14:09
Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!


swc-bump:

  • swc_atoms

@kdy1 kdy1 added this to the Planned milestone Nov 7, 2023
@kdy1 kdy1 changed the title perf(lexer): introduce AtomStoreCell perf(es/lexer): Introduce AtomStoreCell Nov 7, 2023
@kdy1 kdy1 changed the title perf(es/lexer): Introduce AtomStoreCell perf(atoms): Introduce AtomStoreCell Nov 9, 2023
@kdy1 kdy1 merged commit a5a6eb5 into swc-project:main Nov 9, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.97 Nov 9, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.97 Nov 20, 2023
@swc-project swc-project locked as resolved and limited conversation to collaborators Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants