Skip to content

Avoid many cmt allocations. #50418

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
May 5, 2018
Merged

Avoid many cmt allocations. #50418

merged 1 commit into from
May 5, 2018

Conversation

nnethercote
Copy link
Contributor

cmt is a ref-counted wrapper around cmt_ The use of refcounting
keeps cmt handling simple, but a lot of cmt instances are very
short-lived, and heap-allocating the short-lived ones takes up time.

This patch changes things in the following ways.

  • Most of the functions that produced cmt instances now produce cmt_
    instances. The Rc::new calls that occurred within those functions
    now occur at their call sites (but only when necessary, which isn't
    that often).

  • Many of the functions that took cmt arguments now take &cmt_
    arguments. This includes all the methods in the Delegate trait.

As a result, the vast majority of the heap allocations are avoided. In
an extreme case, the number of calls to malloc in tuple-stress drops
from 9.9M to 7.9M, a drop of 20%. And the compile times for many runs of
coercions, deep-vector, and tuple-stress drop by 1--2%.

`cmt` is a ref-counted wrapper around `cmt_` The use of refcounting
keeps `cmt` handling simple, but a lot of `cmt` instances are very
short-lived, and heap-allocating the short-lived ones takes up time.

This patch changes things in the following ways.

- Most of the functions that produced `cmt` instances now produce `cmt_`
  instances. The `Rc::new` calls that occurred within those functions
  now occur at their call sites (but only when necessary, which isn't
  that often).

- Many of the functions that took `cmt` arguments now take `&cmt_`
  arguments. This includes all the methods in the `Delegate` trait.

As a result, the vast majority of the heap allocations are avoided. In
an extreme case, the number of calls to malloc in tuple-stress drops
from 9.9M to 7.9M, a drop of 20%. And the compile times for many runs of
coercions, deep-vector, and tuple-stress drop by 1--2%.
@rust-highfive
Copy link
Contributor

r? @estebank

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 3, 2018
@leonardo-m
Copy link

Could a compiler pass be added to perform this optimization (escape analysis?)?

@estebank
Copy link
Contributor

estebank commented May 3, 2018

LGTM. r? @petrochenkov or @eddyb for a second pair of eyes.

@eddyb
Copy link
Member

eddyb commented May 3, 2018

Welp, all of this ancient code will hopefully go away once MIR borrowck takes over.
But for now, nice wins! @bors r+

@bors
Copy link
Collaborator

bors commented May 3, 2018

📌 Commit 7cf142f has been approved by eddyb

@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-review Status: Awaiting review from the assignee but also interested parties. labels May 3, 2018
@nnethercote
Copy link
Contributor Author

@Manishearth: note that this will break Clippy. The fix will be easy, just updating method arguments for the changes in the Delegate trait.

@Manishearth
Copy link
Member

sounds good, thanks for the heads up!

@petrochenkov petrochenkov assigned eddyb and unassigned petrochenkov May 4, 2018
@bors
Copy link
Collaborator

bors commented May 4, 2018

⌛ Testing commit 7cf142f with merge f86297d51946264715934bafd69c6c9315f80594...

@bors
Copy link
Collaborator

bors commented May 4, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 4, 2018
@nnethercote
Copy link
Contributor Author

The failure is:

thread 'build_script::rename_with_link_search_path' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }

Infrastructure failure? Worth a retry?

@eddyb
Copy link
Member

eddyb commented May 4, 2018

@bors retry

@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-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2018
@kennytm
Copy link
Member

kennytm commented May 4, 2018

cc #48775

@bors
Copy link
Collaborator

bors commented May 5, 2018

⌛ Testing commit 7cf142f with merge a19e9ece9c3a52c20c96c3a6d337c8d193a94e6b...

@bors
Copy link
Collaborator

bors commented May 5, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 5, 2018
@rust-highfive

This comment has been minimized.

1 similar comment
@rust-highfive

This comment has been minimized.

@nnethercote
Copy link
Contributor Author

[01:36:07] test process::tests::test_process_output_fail_to_start ... test process::tests::test_process_output_fail_to_start has been running for over 60 seconds

Which is #43283.

Can somebody please retry?

@Zoxc
Copy link
Contributor

Zoxc commented May 5, 2018

@bors r=eddyb

@bors
Copy link
Collaborator

bors commented May 5, 2018

💡 This pull request was already approved, no need to approve it again.

  • This pull request previously failed. You should add more commits to fix the bug, or use retry to trigger a build again.
  • There's another pull request that is currently being tested, blocking this pull request: Add armv5te-unknown-linux-musl target #50423

@bors
Copy link
Collaborator

bors commented May 5, 2018

📌 Commit 7cf142f has been approved by eddyb

@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-review Status: Awaiting review from the assignee but also interested parties. labels May 5, 2018
@bors
Copy link
Collaborator

bors commented May 5, 2018

⌛ Testing commit 7cf142f with merge e471c20...

bors added a commit that referenced this pull request May 5, 2018
Avoid many `cmt` allocations.

`cmt` is a ref-counted wrapper around `cmt_` The use of refcounting
keeps `cmt` handling simple, but a lot of `cmt` instances are very
short-lived, and heap-allocating the short-lived ones takes up time.

This patch changes things in the following ways.

- Most of the functions that produced `cmt` instances now produce `cmt_`
  instances. The `Rc::new` calls that occurred within those functions
  now occur at their call sites (but only when necessary, which isn't
  that often).

- Many of the functions that took `cmt` arguments now take `&cmt_`
  arguments. This includes all the methods in the `Delegate` trait.

As a result, the vast majority of the heap allocations are avoided. In
an extreme case, the number of calls to malloc in tuple-stress drops
from 9.9M to 7.9M, a drop of 20%. And the compile times for many runs of
coercions, deep-vector, and tuple-stress drop by 1--2%.
@bors
Copy link
Collaborator

bors commented May 5, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing e471c20 to master...

# for free to join this conversation on GitHub. Already have an account? # 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.

10 participants