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 many `cmt` allocations. #50418

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

@nnethercote nnethercote commented May 3, 2018

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
Collaborator

@rust-highfive rust-highfive commented May 3, 2018

r? @estebank

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

@leonardo-m
Copy link

@leonardo-m leonardo-m commented May 3, 2018

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

@estebank
Copy link
Contributor

@estebank estebank commented May 3, 2018

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

@eddyb
Copy link
Member

@eddyb 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
Contributor

@bors bors commented May 3, 2018

📌 Commit 7cf142f has been approved by eddyb

@nnethercote
Copy link
Contributor Author

@nnethercote nnethercote commented May 3, 2018

@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

@Manishearth Manishearth commented May 3, 2018

sounds good, thanks for the heads up!

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

@bors bors commented May 4, 2018

Testing commit 7cf142f with merge f86297d...

bors added a commit that referenced this pull request May 4, 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
Contributor

@bors bors commented May 4, 2018

💔 Test failed - status-appveyor

@nnethercote
Copy link
Contributor Author

@nnethercote nnethercote commented May 4, 2018

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 eddyb commented May 4, 2018

@bors retry

@kennytm
Copy link
Member

@kennytm kennytm commented May 4, 2018

cc #48775

@bors
Copy link
Contributor

@bors bors commented May 5, 2018

Testing commit 7cf142f with merge a19e9ec...

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
Contributor

@bors bors commented May 5, 2018

💔 Test failed - status-travis

@rust-highfive

This comment has been hidden.

1 similar comment
@rust-highfive

This comment has been hidden.

@nnethercote
Copy link
Contributor Author

@nnethercote nnethercote commented May 5, 2018

[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 Zoxc commented May 5, 2018

@bors r=eddyb

@bors
Copy link
Contributor

@bors 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: #50423
@bors
Copy link
Contributor

@bors bors commented May 5, 2018

📌 Commit 7cf142f has been approved by eddyb

@bors
Copy link
Contributor

@bors 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
Contributor

@bors bors commented May 5, 2018

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

@bors bors merged commit 7cf142f into rust-lang:master May 5, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@nnethercote nnethercote deleted the nnethercote:cmt branch May 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants
You can’t perform that action at this time.