-
Notifications
You must be signed in to change notification settings - Fork 760
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
Improve compilation times for projects using PyO3 #1604
Conversation
Sounds like nice savings! Not having reviewed the code, can you say anything about if and where runtime performance could be affected? |
I'll take a look, but initial thoughts are:
|
For 2 - I just spotted bench_pyclass.rs, which looks like a good benchmark of the PyClass initialization logic. |
I think these are the relevant benchmarks -- they look fine to me:
first_time_init comes out a little longer, but it's within the variance of this benchmark (the variance is quite large here). And the rest of the results:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thasks! If tests pass, I'm happy with this. To summarise what I see, it's changing some of the #[pyclass]
instantiation code to use dynamic instead of static calling. That'll marginally affect first time initialization, but the change you detect is within tolerance and this is a cost that'll be paid once per whole-program execution anyway.
The changes to handle_panic
may slightly affect the measurements I just made in #1607, however I think they're a reasonable refactoring and I don't expect to be a major performance issue.
Thanks for the review @davidhewitt. Indeed I don't see a conflict with the approach in #1607, although a compiler optimisation that can improve #1607 (inlining The benefit of having |
👍 agreed. FWIW I'm not sure we're ready yet to guarantee that we won't worsen compile times with future changes to PyO3, however I'm sure I'll be tempted to use |
Thanks again for the contribution! |
These changes reduce the number of lines of LLVM code on the word-count example from 29,299 to 24,980.
Top 10 biggest functions in the binary, as reported by
cargo llvm-lines --release
:Here I am using number of lines of LLVM code as an indicator of overall compilation time. I have a large real-world project that sees a 22% improvement in compilation time on its release build due to these changes.