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

[parallel-queries] Make CrateMetadata::cnum_map immutable #50502

Closed
michaelwoerister opened this issue May 7, 2018 · 5 comments
Closed

[parallel-queries] Make CrateMetadata::cnum_map immutable #50502

michaelwoerister opened this issue May 7, 2018 · 5 comments
Labels
A-parallel-queries Area: Parallel query execution C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. WG-compiler-performance Working group: Compiler Performance

Comments

@michaelwoerister
Copy link
Member

The CrateMetadata::cnum_map field is wrapped in a Lock but it does not seem to be mutated anywhere. Less mutable state is always better. To solve this task, remove the Lock and make things compile again.

cc @rust-lang/wg-compiler-performance

@michaelwoerister michaelwoerister added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. WG-compiler-performance Working group: Compiler Performance A-parallel-queries Area: Parallel query execution labels May 7, 2018
@rleungx
Copy link
Contributor

rleungx commented May 7, 2018

It seems that cnum_map field is mutated here, right?

@michaelwoerister
Copy link
Member Author

@rleungx Oh, you are right of course. In that case, I'll remove the E-easy tag. It's still worth looking into though.

@michaelwoerister michaelwoerister removed the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label May 7, 2018
@michaelwoerister
Copy link
Member Author

#50532 implements a partial solution. We still have a lock, but its around data that is accessed a lot less.

alexcrichton added a commit to alexcrichton/rust that referenced this issue May 10, 2018
… r=Zoxc

Don't use Lock for heavily accessed CrateMetadata::cnum_map.

The `cnum_map` in `CrateMetadata` is used for two things:
1. to map `CrateNums` between crates (used a lot during decoding)
2. to construct the (reverse) post order of the crate graph

For the second case, we need to modify the map after the fact, which is why the map is wrapped in a `Lock`. This is bad for the first case, which does not need the modification and does lots of small reads from the map.

This PR splits case (2) out into a separate `dependencies` field. This allows to make the `cnum_map` immutable (and shifts the interior mutability to a less busy data structure).

Fixes rust-lang#50502

r? @Zoxc
alexcrichton added a commit to alexcrichton/rust that referenced this issue May 10, 2018
… r=Zoxc

Don't use Lock for heavily accessed CrateMetadata::cnum_map.

The `cnum_map` in `CrateMetadata` is used for two things:
1. to map `CrateNums` between crates (used a lot during decoding)
2. to construct the (reverse) post order of the crate graph

For the second case, we need to modify the map after the fact, which is why the map is wrapped in a `Lock`. This is bad for the first case, which does not need the modification and does lots of small reads from the map.

This PR splits case (2) out into a separate `dependencies` field. This allows to make the `cnum_map` immutable (and shifts the interior mutability to a less busy data structure).

Fixes rust-lang#50502

r? @Zoxc
@wesleywiser
Copy link
Member

wesleywiser commented May 11, 2018 via email

@michaelwoerister
Copy link
Member Author

It's partial (because it does not reduce the amount of shared mutable state) but it addresses my main concern by not requiring to keep the cnum_map in a mutex. So it's fine to close this issue, I think.

Removing more mutable state from CrateMetadata would probably require a bigger refactoring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parallel-queries Area: Parallel query execution C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. WG-compiler-performance Working group: Compiler Performance
Projects
None yet
Development

No branches or pull requests

3 participants