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

More efficient try!() alternative #1121

Closed
dtolnay opened this issue Dec 12, 2017 · 5 comments
Closed

More efficient try!() alternative #1121

dtolnay opened this issue Dec 12, 2017 · 5 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented Dec 12, 2017

Our generated code uses the standard try! macro heavily.

match $expr {
    Ok(val) => val,
    Err(err) => {
        return Err(From::from(err))
    }
}

I think practically none of our uses of try! rely on the From::from conversion (i.e. it resolves to the impl From<T> for T). Let's experiment with generating code that omits the conversion and see whether that improves the compile times of the generated code.

@oli-obk
Copy link
Member

oli-obk commented Dec 14, 2017

Do you want a(n allow-by-default) lint for that?

@dtolnay
Copy link
Member Author

dtolnay commented Dec 14, 2017

Thanks! Let's wait until we find out that this helps compile time measurably.

(Or do you mean as a way to help me find all the try! that need to be changed? I'm not worried about that, I can just replace them all and then change back the few that fail to compile.)

@oli-obk
Copy link
Member

oli-obk commented Dec 15, 2017

I meant more to not regress in the future

@dtolnay
Copy link
Member Author

dtolnay commented Apr 19, 2018

Testing against our json-benchmark with --bin json-benchmark --no-default-features --features parse-struct,all-files,lib-serde it looks like the more efficient try!() results in 15% faster "item-bodies checking", 25% faster "borrow checking", 2% faster debug compile overall, 0.6% smaller debug binary, and 0.2% small release binary.

@dtolnay
Copy link
Member Author

dtolnay commented Apr 21, 2018

Maybe the most impactful number: 7% faster cargo check time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants