-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Avoid many cmt
allocations.
#50418
Conversation
`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%.
r? @estebank (rust_highfive has picked a reviewer for you, use r? to override) |
Could a compiler pass be added to perform this optimization (escape analysis?)? |
LGTM. r? @petrochenkov or @eddyb for a second pair of eyes. |
Welp, all of this ancient code will hopefully go away once MIR borrowck takes over. |
📌 Commit 7cf142f has been approved by |
@Manishearth: note that this will break Clippy. The fix will be easy, just updating method arguments for the changes in the |
sounds good, thanks for the heads up! |
⌛ Testing commit 7cf142f with merge f86297d51946264715934bafd69c6c9315f80594... |
💔 Test failed - status-appveyor |
The failure is:
Infrastructure failure? Worth a retry? |
@bors retry |
cc #48775 |
⌛ Testing commit 7cf142f with merge a19e9ece9c3a52c20c96c3a6d337c8d193a94e6b... |
💔 Test failed - status-travis |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
Which is #43283. Can somebody please retry? |
@bors r=eddyb |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit 7cf142f has been approved by |
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%.
☀️ Test successful - status-appveyor, status-travis |
cmt
is a ref-counted wrapper aroundcmt_
The use of refcountingkeeps
cmt
handling simple, but a lot ofcmt
instances are veryshort-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 producecmt_
instances. The
Rc::new
calls that occurred within those functionsnow 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%.