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 source in an Arc<str> #483

Merged
merged 12 commits into from
Jan 5, 2022
Merged

Store source in an Arc<str> #483

merged 12 commits into from
Jan 5, 2022

Conversation

canndrew
Copy link
Contributor

This PR removes the <'sc> lifetime which was on just about every type and function in the codebase. Source code is now stored in an Arc<str> and Span is used to represent a sub-slice of the string.

Copy link
Contributor

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

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

merge conflicts 😬

@adlerjohn adlerjohn assigned adlerjohn and canndrew and unassigned adlerjohn Dec 23, 2021
core_lang/Cargo.toml Outdated Show resolved Hide resolved
@adlerjohn adlerjohn added the compiler General compiler. Should eventually become more specific as the issue is triaged label Dec 23, 2021
@sezna
Copy link
Contributor

sezna commented Dec 23, 2021

I've resolved the conflicts and am preparing this PR to be pulled in, since I'd like it to be in before deploying.

sezna
sezna previously approved these changes Dec 23, 2021
@otrho
Copy link
Contributor

otrho commented Dec 24, 2021

Is there a reason to choose Arc over Rc? Are we going to multithread the compiler?

@canndrew
Copy link
Contributor Author

canndrew commented Jan 4, 2022

I've rebased this off of master.

@canndrew
Copy link
Contributor Author

canndrew commented Jan 4, 2022

Is there a reason to choose Arc over Rc? Are we going to multithread the compiler?

I figured it would be good to leave us with the option to. I don't know how big the performance hit is from using Arc vs Rc, but I could measure it.

Copy link
Contributor

@adlerjohn adlerjohn left a comment

Choose a reason for hiding this comment

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

Clippy CI is failing

@otrho
Copy link
Contributor

otrho commented Jan 4, 2022

Is there a reason to choose Arc over Rc? Are we going to multithread the compiler?

I figured it would be good to leave us with the option to. I don't know how big the performance hit is from using Arc vs Rc, but I could measure it.

The only experience I have is with C++ std::shared_ptr in which case it was worth worrying about when used non-trivially...

@canndrew canndrew force-pushed the canndrew/pest-arc-2 branch from 25351e5 to f9785cf Compare January 5, 2022 06:14
@canndrew canndrew force-pushed the canndrew/pest-arc-2 branch from f9785cf to fe63481 Compare January 5, 2022 06:29
@canndrew
Copy link
Contributor Author

canndrew commented Jan 5, 2022

This is rebased (again) and CI fixed.

The only experience I have is with C++ std::shared_ptr in which case it was worth worrying about when used non-trivially...

C++'s shared_ptr<T> is equivalent to Rust's Rc<T>. Rust's Arc<T> is equivalent to C++'s atomic<shared_ptr<T>>. There will be a performance hit switching to either. I don't know how big the difference will be between Arc and Rc.

@otrho
Copy link
Contributor

otrho commented Jan 5, 2022

C++'s shared_ptr<T> is equivalent to Rust's Rc<T>. Rust's Arc<T> is equivalent to C++'s atomic<shared_ptr<T>>. There will be a performance hit switching to either. I don't know how big the difference will be between Arc and Rc.

It's beside the point here, but shared_ptr is thead safe and maintains a lock. I experienced horrendous perf once in a project which used hundreds of them and it was fixed when refactoring to unique_ptr. So it depends on the execution profile, if we end up with 100s of our Arc<str> and copy them a lot then I imagine perf will be impacted. But only if this is the case. We might not copy these guys around that much.

@sezna
Copy link
Contributor

sezna commented Jan 5, 2022

Looking at the CI runs for this branch vs. master, I don't think there's a significant performance difference. Considering we are single threaded, there's essentially just an extra semaphore and a u64 counting references. I'm gonna go ahead and merge this in, if we want to bench against plain Rc later we can.

@sezna sezna merged commit ff6f914 into master Jan 5, 2022
@sezna sezna deleted the canndrew/pest-arc-2 branch January 5, 2022 13:51
@adlerjohn
Copy link
Contributor

+1 on @sezna's comment to bench first, and if using Arc is a bottleneck then we can optimize when it's an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants