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

./configure --enable-optimizations should enable LTO #89536

Open
vstinner opened this issue Oct 5, 2021 · 16 comments
Open

./configure --enable-optimizations should enable LTO #89536

vstinner opened this issue Oct 5, 2021 · 16 comments
Labels
3.11 build The build process and cross-build

Comments

@vstinner
Copy link
Member

vstinner commented Oct 5, 2021

BPO 45373
Nosy @gpshead, @vstinner, @ned-deily, @methane, @corona10, @pablogsal, @erlend-aasland

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2021-10-05.09:32:25.894>
labels = ['build', '3.11']
title = './configure --enable-optimizations should enable LTO'
updated_at = <Date 2022-03-03.09:51:27.150>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2022-03-03.09:51:27.150>
actor = 'erlendaasland'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Build']
creation = <Date 2021-10-05.09:32:25.894>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 45373
keywords = []
message_count = 9.0
messages = ['403209', '403210', '403211', '403244', '403248', '403249', '414312', '414313', '414316']
nosy_count = 7.0
nosy_names = ['gregory.p.smith', 'vstinner', 'ned.deily', 'methane', 'corona10', 'pablogsal', 'erlendaasland']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue45373'
versions = ['Python 3.11']

@vstinner
Copy link
Member Author

vstinner commented Oct 5, 2021

When Python is configured with:

./configure --enable-optimizations

PGO is enabled but not LTO.

I recall that a few years ago, GCC with LTO had bugs. But now, GCC with LTO is reliable. I suggest to enable it by default in Python 3.11.

Or did I miss a reason to not do that?

@vstinner vstinner added 3.11 build The build process and cross-build labels Oct 5, 2021
@pablogsal
Copy link
Member

pablogsal commented Oct 5, 2021

IIRC activating lto is specially annoying on MacOS due to the need of some llvm components that are a bit hard to get. Let me dig a bit to see if I reproduce the problem

@vstinner
Copy link
Member Author

vstinner commented Oct 5, 2021

Pablo:

IIRC activating lto is specially annoying on MacOS due to the need of some llvm components that are a bit hard to get. Let me dig a bit to see if I reproduce the problem

Ah, I guess that you are referring to this requirement:
"The C compiler Clang requires llvm-ar for LTO (ar on macOS), as well as an LTO-aware linker (ld.gold or lld)."
https://docs.python.org/dev/using/configure.html#cmdoption-with-lto

Maybe configure can enable LTO on all platforms but macOS.

@ned-deily
Copy link
Member

ned-deily commented Oct 5, 2021

IIRC activating lto is specially annoying on MacOS due to the need of some llvm components that are a bit hard to get

Can you say more? We are currently using --with-lto with a vanilla Apple Command Line Tools (or Xcode) for macOS installer builds when building on macOS 10.15 High Sierra or higher. Perhaps this was just an issue on older versions.

@pablogsal
Copy link
Member

pablogsal commented Oct 5, 2021

Yeah, I had problems in the past to get llvm-ar or some other component. I still need time to reproduce and to see if this still happens on new versions.

@ned-deily
Copy link
Member

ned-deily commented Oct 5, 2021

I don't think you need llvm-ar anymore with the Apple Tool Chain but let me look into it as I have all the relevant previous macOS releases as VMs to test with.

@gpshead
Copy link
Member

gpshead commented Mar 1, 2022

FWIW I agree that we should try adding LTO to --enable-optimizations now.

@ned-deily
Copy link
Member

ned-deily commented Mar 1, 2022

Sorry, this slipped off my radar and I haven't gone back and checked older versions of macOS. But it certainly is true that at least with the current versions of the Apple Developer Tools (either the Command Line Tools or Xcode) for macOS 11 (Big Sur) and macOS 12 (Monterey), things just work.

@methane
Copy link
Member

methane commented Mar 1, 2022

Can we use --lto=thin when availabe?
And can we not use --lto when building profiling python?

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@nascheme
Copy link
Member

nascheme commented Apr 11, 2022

One data point: when I enabled --with-lto, the cpython build task failed on my container build host due to an out of memory condition. It seems that gcc uses a lot more RAM in that case (host has 2 GB, I think). I fixed it by adding a swap file but I suspect if we make it to default on, more people will run into the issue.

@corona10
Copy link
Member

corona10 commented Apr 13, 2022

@methane san cc @ned-deily

I would like to switch the default LTO policy to the thinLTO if available from Python3.12.
The thinLTO option is only introduced from Python3.11 so let's leave this option as an experimental choice for Python 3.11 :)

AS-IS

./configure --with-lto  # fullLTO
./configure --with-lto=full  # fullLTO
./configure --with-lto=thin  # thinLTO

##TO-BE

./configure --with-lto # thinLTO if possible if not fullLTO
./configure --with-lto=full  # fullLTO
./configure --with-lto=thin  # thinLTO

@methane
Copy link
Member

methane commented Apr 13, 2022

I like faster LTO by default. Because default LTO is slow.

Random comments:

I don't want to use LTO while profiling build (1st build in PGO).

What about GCC? GCC supports -flto=auto option since GCC 10.
https://www.phoronix.com/scan.php?page=news_item&px=GCC-flto-auto-option

@ned-deily
Copy link
Member

ned-deily commented Apr 13, 2022

I don't have an opinion yet. I plan to compare both options on macOS.

@corona10
Copy link
Member

corona10 commented Apr 13, 2022

I don't want to use LTO while profiling build (1st build in PGO).

+1

What about GCC? GCC supports -flto=auto option since GCC 10

We may need to add the option for ./configure --with-lto=auto and I think that we have a chance to add it to Python 3.11
Also in that case, from Python 3.12 ./configure --with-lto should use auto option if available, if not should use the default LTO policy for GCC.

@vstinner
Copy link
Member Author

vstinner commented Sep 22, 2022

So. Can we enable LTO in Python 3.12? Is there a way to opt-out from LTO when --enable-optimizations is used? For example, does ./configure --enable-optimizations --without-lto work as expected?

@vstinner
Copy link
Member Author

vstinner commented Sep 22, 2022

Is it possible to disable LTO if it's known to not work properly / if the toolchain is too old? I'm thinking at Ned's toolchain to build Python on macOS for x86 CPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 build The build process and cross-build
Projects
None yet
Development

No branches or pull requests

7 participants