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

Avoid allocations in Decoder::read_str. #37064

Merged
merged 1 commit into from
Oct 13, 2016
Merged

Conversation

nnethercote
Copy link
Contributor

opaque::Decoder::read_str is very hot within rustc due to its use in
the reading of crate metadata, and it currently returns a String. This
commit changes it to instead return a Cow<str>, which avoids a heap
allocation.

This change reduces the number of calls to malloc by almost 10% in
some benchmarks.

This is a [breaking-change] to libserialize.

@rust-highfive
Copy link
Collaborator

r? @erickt

(rust_highfive has picked a reviewer for you, use r? to override)

@nnethercote
Copy link
Contributor Author

r? @eddyb

@nnethercote
Copy link
Contributor Author

(This is a carry-over of #37022 because I borked my git clone.)

@eddyb
Copy link
Member

eddyb commented Oct 9, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Oct 9, 2016

📌 Commit d6117f8 has been approved by eddyb

`opaque::Decoder::read_str` is very hot within `rustc` due to its use in
the reading of crate metadata, and it currently returns a `String`. This
commit changes it to instead return a `Cow<str>`, which avoids a heap
allocation.

This change reduces the number of calls to `malloc` by almost 10% in
some benchmarks.

This is a [breaking-change] to libserialize.
@nnethercote
Copy link
Contributor Author

@eddyb: bleh, I pushed with some uncommitted changes. New version should be better.

@eddyb
Copy link
Member

eddyb commented Oct 9, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Oct 9, 2016

📌 Commit b043e11 has been approved by eddyb

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Oct 11, 2016
Avoid allocations in `Decoder::read_str`.

`opaque::Decoder::read_str` is very hot within `rustc` due to its use in
the reading of crate metadata, and it currently returns a `String`. This
commit changes it to instead return a `Cow<str>`, which avoids a heap
allocation.

This change reduces the number of calls to `malloc` by almost 10% in
some benchmarks.

This is a [breaking-change] to libserialize.
bors added a commit that referenced this pull request Oct 12, 2016
Rollup of 10 pull requests

- Successful merges: #36692, #36743, #36762, #36991, #37023, #37050, #37056, #37064, #37066, #37067
- Failed merges:
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 12, 2016
Avoid allocations in `Decoder::read_str`.

`opaque::Decoder::read_str` is very hot within `rustc` due to its use in
the reading of crate metadata, and it currently returns a `String`. This
commit changes it to instead return a `Cow<str>`, which avoids a heap
allocation.

This change reduces the number of calls to `malloc` by almost 10% in
some benchmarks.

This is a [breaking-change] to libserialize.
bors added a commit that referenced this pull request Oct 12, 2016
@bors bors merged commit b043e11 into rust-lang:master Oct 13, 2016
@nnethercote nnethercote deleted the read_str branch October 13, 2016 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants