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

lookup exported symbols only when needed. #48219

Merged
merged 1 commit into from
Feb 24, 2018

Conversation

andjo403
Copy link
Contributor

@andjo403 andjo403 commented Feb 14, 2018

reduces the time to compile small file with no optimization by half.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@andjo403
Copy link
Contributor Author

andjo403 commented Feb 14, 2018

half the time was only for an empty file due to I measured wrong (had --crate-type lib for a file with only an main function ) but hay big win for #43300 :) for other files the translation time go down 10ms so 3-4%

@Mark-Simulacrum
Copy link
Member

Could you make the exported_symbols map be an Option so that it's very clear if in the future this optimization no longer makes sense we don't end up checking an empty map and not realizing it.

Otherwise I feel pretty good about this!

r? @Mark-Simulacrum

@pietroalbini pietroalbini added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 14, 2018
@andjo403
Copy link
Contributor Author

@Mark-Simulacrum shall I split it up in two optional variables then one for local create and other? or shall I only have one if with lto or not? And what shall I do in lto.rs when there is none in the variable?

is it possible to move this to the use in lto.rs my feeling was that it was not wanted/possible.

will try to fix this after work today

@michaelwoerister
Copy link
Member

One field for the whole list is fine. In lto.rs you can call Option::expect() so that the compiler ICEs if we have a None value. Crashing is fine, since there should never be a None value if the conditions for filling the list are set up correctly.

for &cnum in tcx.crates().iter() {
exported_symbols.insert(cnum, tcx.exported_symbols(cnum));
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you turn this whole block into a match tcx.sess.lto() { ... } instead of two nested ifs? It's a bit more verbose but it makes it easier to read.

@michaelwoerister
Copy link
Member

Great find, btw!

@andjo403
Copy link
Contributor Author

I'm not sure this PR was a good idea.
yes I get some improvements when i compile with "--emit=dep-info,metadata" but when linking is done it takes more time to compile.
have done the tested with the random small file: /src/test/run-pass/ctfe/assoc-const.rs.
from time-passes i get before this PR:
time: 0.062; rss: 118MB translation
time: 0.139; rss: 122MB linking
and with this PR:
time: 0.053; rss: 114MB translation
time: 0.189; rss: 119MB linking
so even if there is a gains in translation there is a bigger lose in the linking.
so do not know if this PR shall be continued.

also I'm to bad at rust to understand how to update the code in lto.rs if I change to a Arc<Option> when I try to get the value with the Option::expect() I get a compile error and I do not understand how to solve it.
125 | let exported_symbols = cgcx.exported_symbols.expect("needs exported symbols"); | ^^^^^^^^^^^^^^^^^^^^^ cannot move out of borrowed content

@Mark-Simulacrum
Copy link
Member

This should have no effect on linking time, though perhaps that incorporates parts of Rust code too. I'm not sure. I don't see why this would be a net loss.

With regards to the option, you probably want something like cgcs.exported_symbols.as_ref().expect("...") or maybe as_mut() if we mutate them, but I don't think we do.

@andjo403
Copy link
Contributor Author

have already tried with as_ref and get the same error :(
about the linktime the only thing that I can think of is that some queries is done in some other order.
When I was looking at the profile logs it was the symbol_name query that was the main time consumer of the export_symbol query as I was understanding it.

@andjo403
Copy link
Contributor Author

got it to compile now have no idea why :)
let exported_symbols = (*cgcx.exported_symbols).as_ref().expect("needs exported symbols");

@Mark-Simulacrum
Copy link
Member

Ah, the as_ref() call was being called on the Arc instead of the Option, so deref-ing the option first solved the problem.

@Mark-Simulacrum
Copy link
Member

It'd actually be nice to flip the Arc and the Option since right now we're still allocating space for the Some variant even when we don't use that space. Very minor optimization, but seems like a trivial change that we should make -- if only for code clarity.

reduces the time to emit dep-info and metadata.
@andjo403
Copy link
Contributor Author

started with that order of Arc and the Option but when I did not get it to compile I changed thanks for the comments.

@michaelwoerister
Copy link
Member

yes I get some improvements when i compile with "--emit=dep-info,metadata" but when linking is done it takes more time to compile.

Linking needs the list of exported symbols too, so it will be computed there instead of earlier. However, the overall time should be the same in that case, while can skip computing the list in cases without linking. It would be great if you could verify this though (that the overall build time is roughly the same for builds that do linking).

@andjo403
Copy link
Contributor Author

the time-passes listed abow is what differs between the runs so when linking I see a 40ms longer compile time with this PR.
so the question is why the query of exported symbols take more time in the linking pass.
will try to figure out why I get a longer link time during the weekend.

@andjo403
Copy link
Contributor Author

the function that takes longer time is this

fn exec_linker(sess: &Session, cmd: &mut Command, tmpdir: &Path)

but I do not see how this PR change any thing in that function very strange.

@michaelwoerister
Copy link
Member

That's weird. Let's test it perf.rust-lang.org to see if the difference is visible there too.

@bors try

@bors
Copy link
Contributor

bors commented Feb 19, 2018

⌛ Trying commit 7041ef3 with merge 682bc88...

bors added a commit that referenced this pull request Feb 19, 2018
lookup exported symbols only when needed.

reduces the time to compile small file with no optimization by half.
@bors
Copy link
Contributor

bors commented Feb 19, 2018

☀️ Test successful - status-travis
State: approved= try=True

@michaelwoerister
Copy link
Member

@Mark-Simulacrum, could you do a perf run please?

@Mark-Simulacrum
Copy link
Member

Must've forgot to leave a comment that I queued it. http://perf.rust-lang.org/compare.html?start=27a046e9338fb0455c33b13e8fe28da78212dedc&end=682bc88006582c2e549d0c5b26a1f41a682f2a18&stat=instructions%3Au (done). Looks fairly good overall.

@andjo403
Copy link
Contributor Author

have tested om my other computer and can not see any degradation of the compile time when linking.
In the perf run I have no idea what the problem whit style-servo-opt is.

@goffrie
Copy link
Contributor

goffrie commented Feb 20, 2018

@andjo403 "style-servo-opt clean incremental" is flaky so you can ignore it (check out the front page http://perf.rust-lang.org/). So, nice wins all around :)

@Mark-Simulacrum
Copy link
Member

r? @michaelwoerister

@michaelwoerister
Copy link
Member

Wow, surprisingly good even! I guess with this we can skip computing upstream symbol names for rlibs entirely. Awesome find, @andjo403!

@bors r+

@bors
Copy link
Contributor

bors commented Feb 21, 2018

📌 Commit 7041ef3 has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 21, 2018
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 23, 2018
…erister

lookup exported symbols only when needed.

reduces the time to compile small file with no optimization by half.
bors added a commit that referenced this pull request Feb 23, 2018
Rollup of 12 pull requests

- Successful merges: #47933, #48072, #48083, #48123, #48157, #48219, #48221, #48245, #48429, #48436, #48438, #48472
- Failed merges:
bors added a commit that referenced this pull request Feb 24, 2018
Rollup of 12 pull requests

- Successful merges: #47933, #48072, #48083, #48123, #48157, #48219, #48221, #48245, #48429, #48436, #48438, #48472
- Failed merges:
@bors bors merged commit 7041ef3 into rust-lang:master Feb 24, 2018
@andjo403 andjo403 deleted the export_symbol branch February 24, 2018 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants