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

Refactored code to access TLS only in case of panic #34836

Merged
merged 1 commit into from
Jul 16, 2016

Conversation

nikhilshagri
Copy link
Contributor

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@alexcrichton
Copy link
Member

Thanks @cynicaldevil! Two things I'm curious about:

  • Could the debug_assert! be moved to the happen just before the return? It shouldn't be perf sensitive and should be a valid assertion for both paths.
  • Could you take a look at some benchmark numbers and see how much this affects the perf of a no-panic catch_unwind?

@nikhilshagri
Copy link
Contributor Author

Sure! no problem.
On 15 Jul 2016 10:12 pm, "Alex Crichton" notifications@github.com wrote:

Thanks @cynicaldevil https://github.com/cynicaldevil! Two things I'm
curious about:

  • Could the debug_assert! be moved to the happen just before the return?
    It shouldn't be perf sensitive and should be a valid assertion for both
    paths.
  • Could you take a look at some benchmark numbers and see how much
    this affects the perf of a no-panic catch_unwind?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34836 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AKvBjqgVYZk8wg6LzkMSG5Ous23ln6iUks5qV7hYgaJpZM4JNgaz
.

@nikhilshagri
Copy link
Contributor Author

do I need to pass additional flags while compiling or is the - -bench
flag enough?
On 15 Jul 2016 10:34 pm, "Nikhil Shagrithaya" nikhilshagri@gmail.com
wrote:

Sure! no problem.
On 15 Jul 2016 10:12 pm, "Alex Crichton" notifications@github.com wrote:

Thanks @cynicaldevil https://github.com/cynicaldevil! Two things I'm
curious about:

  • Could the debug_assert! be moved to the happen just before the
    return? It shouldn't be perf sensitive and should be a valid
    assertion for both paths.
  • Could you take a look at some benchmark numbers and see how much
    this affects the perf of a no-panic catch_unwind?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#34836 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKvBjqgVYZk8wg6LzkMSG5Ous23ln6iUks5qV7hYgaJpZM4JNgaz
.

@alexcrichton
Copy link
Member

Yeah you'll want something like:

#![feature(test)]
extern crate test;

#[bench]
fn foo(bh: &mut test::Bencher) {
    bh.iter(|| /* thing to benchmark */);
}
$ rustc --test foo.rs -O
$ ./foo --bench

@nikhilshagri
Copy link
Contributor Author

nikhilshagri commented Jul 15, 2016

I put the assert statement before the return now, and also ran the benchmarks:

#![feature(test)]
#![allow(warnings)]
extern crate test;

use std::panic::catch_unwind;

#[bench]
fn test_panic(bh: &mut test::Bencher) {
    bh.iter(|| {
        catch_unwind(|| {
          println!("Hello World!");
        });
    });
}

my-toolchain

bench:       5,995 ns/iter (+/- 1,333)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

nightly

bench:       6,030 ns/iter (+/- 1,330)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

Tbh, there isn't much of a difference, I ran these a few times and the time difference was always in the range of 100ns. Sometimes, the nightly was faster than my custom build. Tested on Ubuntu.

@alexcrichton
Copy link
Member

Oh actually could this be just a micro-benchmark for catch_unwind performance? For example, just:

catch_unwind(|| {})

It's true yeah that catch_unwind should always be dwarfed by I/O

@nikhilshagri
Copy link
Contributor Author

@alexcrichton Here it is:

#![feature(test)]
#![allow(warnings)]
extern crate test;

use std::panic::catch_unwind;

#[bench]
fn test_panic(bh: &mut test::Bencher) {
    bh.iter(|| {
        catch_unwind(|| {});
    });
}

my-toolchain

running 1 test
test test_panic ... bench:          12 ns/iter (+/- 1)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

nightly

running 1 test
test test_panic ... bench:          13 ns/iter (+/- 8)

test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured

@alexcrichton
Copy link
Member

@bors: r+ b28e9dc

Ok, so not a huge win perhaps on Linux, (verified locally as well), but I suspect on WIndows this will make it much faster!

@alexcrichton alexcrichton merged commit d5b9850 into rust-lang:master Jul 16, 2016
@alexcrichton
Copy link
Member

Oh dear, shouldn't have hit the merge button...

I guess let's see if it passes!

@eddyb
Copy link
Member

eddyb commented Jul 16, 2016

@TimNN
Copy link
Contributor

TimNN commented Jul 16, 2016

eddyb added a commit to eddyb/rust that referenced this pull request Jul 16, 2016
…=eddyb

Revert rust-lang#34836 "Refactored code to access TLS only in case of panic"

It has likely caused the last two builds to fail:

* https://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt-rustbuild/builds/1774
* https://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt-rustbuild/builds/1776

(the PR was accidentally merged without going through @bors).
alexcrichton added a commit that referenced this pull request Jul 16, 2016
Revert #34836 "Refactored code to access TLS only in case of panic"
@alexcrichton
Copy link
Member

Yeah sorry about that! I've merged the revert, @cynicaldevil would you mind reopening and I'll r+ correctly this time around?

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.

5 participants