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

Optimize `write_metadata`. #37267

Merged
merged 1 commit into from Oct 19, 2016
Merged

Optimize `write_metadata`. #37267

merged 1 commit into from Oct 19, 2016

Conversation

@nnethercote
Copy link
Contributor

nnethercote commented Oct 19, 2016

write_metadata currently generates metadata unnecessarily in some
cases, and also compresses it unnecessarily in some cases. This commit
fixes that. It speeds up three of the rustc-benchmarks by 1--4%.

r? @eddyb, who deserves much of the credit because he (a) identified the problem from the profile data I provided in #37086, and (b) explained to me how to fix it. Thank you, @eddyb!

@nnethercote

This comment has been minimized.

Copy link
Contributor Author

nnethercote commented Oct 19, 2016

Measurements for a stage1 compiler doing debug builds:

futures-rs-test  4.147s vs  4.175s --> 0.993x faster (variance: 1.012x, 1.009x)
helloworld       0.223s vs  0.224s --> 0.992x faster (variance: 1.011x, 1.006x)
html5ever-2016-  5.182s vs  5.129s --> 1.010x faster (variance: 1.006x, 1.008x)
hyper.0.5.0      4.772s vs  4.754s --> 1.004x faster (variance: 1.012x, 1.007x)
inflate-0.1.0    4.524s vs  4.512s --> 1.003x faster (variance: 1.003x, 1.020x)
issue-32062-equ  0.323s vs  0.322s --> 1.003x faster (variance: 1.009x, 1.023x)
issue-32278-big  1.653s vs  1.661s --> 0.995x faster (variance: 1.004x, 1.009x)
jld-day15-parse  1.460s vs  1.462s --> 0.999x faster (variance: 1.016x, 1.009x)
piston-image-0. 11.318s vs 11.308s --> 1.001x faster (variance: 1.007x, 1.063x)
regex.0.1.30     2.414s vs  2.312s --> 1.044x faster (variance: 1.013x, 1.019x)
rust-encoding-0  1.990s vs  1.979s --> 1.005x faster (variance: 1.008x, 1.007x)
syntex-0.42.2   29.514s vs 29.446s --> 1.002x faster (variance: 1.013x, 1.008x)
syntex-0.42.2-i 15.318s vs 14.959s --> 1.024x faster (variance: 1.059x, 1.006x)

So it's a big win for regex, a moderate win for syntax-incr, a small win for html5ever, and makes little difference to the others. (I did multiple timing runs and these outcomes were consistent.)

.iter()
.map(to_kind)
.max()
.unwrap();

This comment has been minimized.

Copy link
@eddyb

eddyb Oct 19, 2016

Member

This could be written on one line, with the closure passed to it directly, and with no explicit type on the closure argument.
.max().unwrap() would come on the same line after the }) where the } is the closing bracket of the closure.
Also, you might want to do .unwrap_or(MetadataKind::None) instead of .unwrap() (cc @alexcrichton).

This comment has been minimized.

Copy link
@nnethercote

nnethercote Oct 19, 2016

Author Contributor

I fixed the indentation.

@alexcrichton: the specific question is this: in write_metadata, can cx.sess().crate_types be empty?

`write_metadata` currently generates metadata unnecessarily in some
cases, and also compresses it unnecessarily in some cases. This commit
fixes that. It speeds up three of the rustc-benchmarks by 1--4%.
config::CrateTypeDylib |
config::CrateTypeProcMacro => MetadataKind::Compressed,
}
}).max().unwrap();

This comment has been minimized.

Copy link
@eddyb

eddyb Oct 19, 2016

Member

@alexcrichton r=me if the unwrap isn't wrong here.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Oct 19, 2016

@bors: r=eddyb

On Tuesday, October 18, 2016, Eduard-Mihai Burtescu <
notifications@github.com> wrote:

@eddyb commented on this pull request.

In src/librustc_trans/base.rs
#37267 (review):

  •    Uncompressed,
    
  •    Compressed
    
  • }
  • let kind = cx.sess().crate_types.borrow().iter().map(|ty| {
  •    match *ty {
    
  •        config::CrateTypeExecutable |
    
  •        config::CrateTypeStaticlib |
    
  •        config::CrateTypeCdylib => MetadataKind::None,
    
  •        config::CrateTypeRlib => MetadataKind::Uncompressed,
    
  •        config::CrateTypeDylib |
    
  •        config::CrateTypeProcMacro => MetadataKind::Compressed,
    
  •    }
    
  • }).max().unwrap();

@alexcrichton https://github.com/alexcrichton r=me if the unwrap isn't
wrong here.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#37267 (review),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAD95KDALZ8ApEOShtYia3TaL_UNoQbaks5q1ZbjgaJpZM4KagGJ
.

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 19, 2016

📌 Commit 016f69f has been approved by eddyb

eddyb added a commit to eddyb/rust that referenced this pull request Oct 19, 2016
…ddyb

Optimize `write_metadata`.

`write_metadata` currently generates metadata unnecessarily in some
cases, and also compresses it unnecessarily in some cases. This commit
fixes that. It speeds up three of the rustc-benchmarks by 1--4%.

r? @eddyb, who deserves much of the credit because he (a) identified the problem from the profile data I provided in rust-lang#37086, and (b) explained to me how to fix it. Thank you, @eddyb!
bors added a commit that referenced this pull request Oct 19, 2016
Rollup of 23 pull requests

- Successful merges: #36964, #37108, #37117, #37124, #37161, #37176, #37182, #37193, #37198, #37202, #37208, #37218, #37221, #37224, #37230, #37231, #37233, #37236, #37240, #37254, #37257, #37265, #37267
- Failed merges: #37213, #37220, #37261
@bors bors merged commit 016f69f into rust-lang:master Oct 19, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@nnethercote nnethercote deleted the nnethercote:opt-write_metadata branch Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.