-
Notifications
You must be signed in to change notification settings - Fork 50
Change MSBuild to use the Clang backend #690
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
Comments
Last time I ran benchmarks, clang wasn't any better than MSVC on Windows (the clang-cl support works because I updated it to run this benchmark). It's also a really significant compatibility change, and there will certainly be users who want to keep building with MSVC. So I don't think we get to drop support entirely - it may only impact the python.org releases (possibly excluding the Store package, I'm not sure if clang support extends that far). Personally, I doubt it's worth the effort. But if someone wants to make the effort to show that it's both faster and remains binary compatible1, then go for it. Footnotes
|
@erozenfeld thank you for your attention. Sorry if I seem like I'm dunking on the MSVC compiler in the initial issue. If it seems overly negative, I'm sorry about that. Yes the link is #321 instead. But out of all the links, the only actionable one I think is python/cpython#121263. We've had a problem where Thank you for your time! |
@Fidget-Spinner Thank you for the clarification. I spent some time looking at python/cpython#121263. I found one compiler issue you are running into. Normally we compile functions in a bottom-up call graph order, i.e. callees before callers. That way we have more information for optimizations, including inlining. However, with multi-threaded compilation we schedule huge functions for earlier compilation in order to improve the overall multithreaded compilation time. The downside is that these huge functions don't always have information about callees, which results in worse code generation (and worse inlining decisions) for these huge functions. We are considering disabling that scheduling tweak for PGO (or perhaps for huge functions that are hot according to PGO info). In the meantime we have a switch that disables that: |
One more note: the compilation order scheduling tweak mentioned above affects not only |
I'll run a build with |
The I took the parent of python/cpython#121270, 93156880efd14ad7adc7d3512552b434f5543890, which still used To confirm this, I am going to run 2 more experiments over the weekend:
|
The results are in:
(All of this is with PGO, as is all of our benchmarking). So, it's clear that the flag helps (2% wins are hard to come by), and perhaps we should always use it for PGO builds (where the slower build times are already expected). But it's also clear that the macros (forcible inlining) are still helpful. Thanks again for all your help on this @erozenfeld. I'd be happy to help benchmark any ways to tweak the inlining heuristics that you think might be helpful. |
@zooba I'd like to restart this discussion. Clang now promises ABI compatibility with MSVC for everything we care about in CPython https://clang.llvm.org/docs/MSVCCompatibility.html Would you be open to allowing a clang backend specified in the MSBuild solutions file? With the new tail calling interpreter, clang 19 is a significant step up in performance, even with no PGO on. We can keep the MSBuild backend as an alternative in This isn't just for perf reasons too. @colesbury has mentioned multiple times to consider switching to clang because it's blocking some work we (both Meta and Faster CPython) want to do on StackRefs in CPython. We need StackRefs to make free-threading the default too. So there's multiple incentives here. |
Update We have official binary release for clang 19.1.0 for Windows FYI https://github.com/llvm/llvm-project/releases/tag/llvmorg-19.1.0 I will test the workflow this week I can work on this issue.
|
@Zheaoli thanks for taking this up! You might want to wait for @mdboom to give some suggestions too on Monday. He's made some changes to bench runner to work with clang. Apparently it's just a one line change here https://github.com/faster-cpython/bench_runner/blob/164361bbb9a82dcb9bdaba8f155d18f4629b0b1a/bench_runner/templates/_benchmark.src.yml#L115 (see the additional inputs.clang options). |
Chrome is using clang-cl now for quite some time: https://blog.llvm.org/2018/03/clang-is-now-used-to-build-chrome-for.html
I've done some small changes to enable PGO in case of clang-cl. I can craft a pull request, if there is interest on it. Likewise, I've spotted some places where we could adapt some But I think all that would need a build bot first? |
@chris-eibl can you open a draft PR please so we can estimate how much effort this is? @Zheaoli sorry I think Chris might take over this as he seems like he already has something working. Though I might still need your help testing this. |
No problem, it's ok for me lol |
Draft PR is here: python/cpython#129907 Help and feedback more than welcome :) |
Hi, I would like to drop some requests for this issue
I usually add these properties to compile python with clang-cl Directory.build.props
pyproject.props
|
This has too much splash radius and requires a PEP. So I'm closing this. We will add build support for clang-cl in the Windows builds but won't switch to it as default. |
MSBuild has supported using clang backend for awhile now. https://learn.microsoft.com/en-us/cpp/build/clang-support-msbuild?view=msvc-170
MSVC has been somewhat unpredictable in comparison to the other compilers. We've had reports that it does not benefit from Python 3.11 1, of random slowdowns 2, of ceval.c being too big for MSVC to inline/optimize properly 3, and now, slowdowns that only hit it and no other platform 4.
We should seriously consider switching to another compiler, because it's starting to hinder our own productivity and performance goals on Windows.
The text was updated successfully, but these errors were encountered: