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 quadratic growth of functions due to cleanups #31390

Merged
merged 1 commit into from
Feb 5, 2016

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Feb 3, 2016

If a new cleanup is added to a cleanup scope, the cached exits for that
scope are cleared, so all previous cleanups have to be translated
again. In the worst case this means that we get N distinct landing pads
where the last one has N cleanups, then N-1 and so on.

As new cleanups are to be executed before older ones, we can instead
cache the number of already translated cleanups in addition to the
block that contains them, and then only translate new ones, if any and
then jump to the cached ones, getting away with linear growth instead.

For the crate in #31381 this reduces the compile time for an optimized
build from >20 minutes (I cancelled the build at that point) to about 11
seconds. Testing a few crates that come with rustc show compile time
improvements somewhere between 1 and 8%. The "big" winner being
rustc_platform_intrinsics which features code similar to that in #31381.

Fixes #31381

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

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

@Gankra
Copy link
Contributor

Gankra commented Feb 3, 2016

Awesome stuff @dotdash! 🌴

exit_label.branch(bcx_out, prev_llbb);
prev_llbb = bcx_in.llbb;

scope.add_cached_early_exit(exit_label, prev_llbb);
let len = scope.cleanups.len();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move this a little bit up and reuse len inside take(scope.cleanups.len() - skip).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@nagisa
Copy link
Member

nagisa commented Feb 3, 2016

Overall LGTM.

@dotdash
Copy link
Contributor Author

dotdash commented Feb 3, 2016

Nits addressed.

@jonas-schievink
Copy link
Contributor

No test?

@dotdash
Copy link
Contributor Author

dotdash commented Feb 3, 2016

Test added.

@nagisa
Copy link
Member

nagisa commented Feb 3, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Feb 3, 2016

📌 Commit 8923122 has been approved by nagisa

// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
// CHECK: call{{.*}}SomeUniqueName{{.*}}drop
// CHECK-NOT: call{{.*}}SomeUniqueName{{.*}}drop
// The next line checks for the 0 that ends the function definition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0 is a typo'd }, right?

If a new cleanup is added to a cleanup scope, the cached exits for that
scope are cleared, so all previous cleanups have to be translated
again. In the worst case this means that we get N distinct landing pads
where the last one has N cleanups, then N-1 and so on.

As new cleanups are to be executed before older ones, we can instead
cache the number of already translated cleanups in addition to the
block that contains them, and then only translate new ones, if any and
then jump to the cached ones, getting away with linear growth instead.

For the crate in rust-lang#31381 this reduces the compile time for an optimized
build from >20 minutes (I cancelled the build at that point) to about 11
seconds. Testing a few crates that come with rustc show compile time
improvements somewhere between 1 and 8%. The "big" winner being
rustc_platform_intrinsics which features code similar to that in rust-lang#31381.

Fixes rust-lang#31381
@dotdash
Copy link
Contributor Author

dotdash commented Feb 3, 2016

@bors r=nagisa

Typo fixed.

@bors
Copy link
Contributor

bors commented Feb 3, 2016

📌 Commit 8c0f4f5 has been approved by nagisa

@bluss bluss added the relnotes Marks issues that should be documented in the release notes of the next release. label Feb 4, 2016
Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 5, 2016
If a new cleanup is added to a cleanup scope, the cached exits for that
scope are cleared, so all previous cleanups have to be translated
again. In the worst case this means that we get N distinct landing pads
where the last one has N cleanups, then N-1 and so on.

As new cleanups are to be executed before older ones, we can instead
cache the number of already translated cleanups in addition to the
block that contains them, and then only translate new ones, if any and
then jump to the cached ones, getting away with linear growth instead.

For the crate in rust-lang#31381 this reduces the compile time for an optimized
build from >20 minutes (I cancelled the build at that point) to about 11
seconds. Testing a few crates that come with rustc show compile time
improvements somewhere between 1 and 8%. The "big" winner being
rustc_platform_intrinsics which features code similar to that in rust-lang#31381.

Fixes rust-lang#31381
@bors
Copy link
Contributor

bors commented Feb 5, 2016

⌛ Testing commit 8c0f4f5 with merge 38dfb96...

bors added a commit that referenced this pull request Feb 5, 2016
If a new cleanup is added to a cleanup scope, the cached exits for that
scope are cleared, so all previous cleanups have to be translated
again. In the worst case this means that we get N distinct landing pads
where the last one has N cleanups, then N-1 and so on.

As new cleanups are to be executed before older ones, we can instead
cache the number of already translated cleanups in addition to the
block that contains them, and then only translate new ones, if any and
then jump to the cached ones, getting away with linear growth instead.

For the crate in #31381 this reduces the compile time for an optimized
build from >20 minutes (I cancelled the build at that point) to about 11
seconds. Testing a few crates that come with rustc show compile time
improvements somewhere between 1 and 8%. The "big" winner being
rustc_platform_intrinsics which features code similar to that in #31381.

Fixes #31381
@bors bors merged commit 8c0f4f5 into rust-lang:master Feb 5, 2016
@dotdash dotdash deleted the fix_quadratic_drop branch March 18, 2016 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants