Skip to content

Conversation

@hroncok
Copy link
Contributor

@hroncok hroncok commented Nov 20, 2025

@hroncok
Copy link
Contributor Author

hroncok commented Nov 20, 2025

I opened this as a draft, because keeping the files from being deleted when make clean is run might be surprising for somebody. An alternative solution for Fedora would be to add something like --with-jit-stencils PATH to configure, which would replace JIT building with copying. However, I still think that building the JIT files multiple times during a PGO build is wasting resources.

@hroncok hroncok marked this pull request as ready for review November 26, 2025 11:12
@emmatyping
Copy link
Member

emmatyping commented Nov 26, 2025

My understanding of clean-retain-profile is that it is meant to remove files that depend on PYTHON_FOR_REGEN, since that will change between the PGO run and the final build. If that is correct, then I would say the stencils should be rm'd in make clean and make distclean, but should not change with make clean-retain-profile, since, as I understand it, the JIT stencils do not depend on the Python binary used other than platform information (which should not change across executables for the same host and build).

So I would suggest making a new target clean-jit-stencils which will be a dep of distclean and clean but not clean-retain-profile

@hroncok
Copy link
Contributor Author

hroncok commented Nov 26, 2025

However, when the stencils are removed in make clean, they are apparently also removed during the pgo task that calls it. I have not yet figured out why and where make clean is called.

@hroncok
Copy link
Contributor Author

hroncok commented Nov 26, 2025

Ah:

cpython/Makefile.pre.in

Lines 838 to 841 in bc9e63d

# Profile generation build must start from a clean tree.
profile-clean-stamp:
$(MAKE) clean
touch $@

So the problem with my approach is that by dropping in the prebuilt stencils before this runs, they are deleted here. That's probably only problematic for my use case :/

@hroncok hroncok marked this pull request as draft November 27, 2025 13:16
@hroncok
Copy link
Contributor Author

hroncok commented Nov 27, 2025

So, I modified the behavior to keep removing the stencils with make clean but not run make clean during the PTO build. I think this is cleaner.

@hroncok hroncok marked this pull request as ready for review November 27, 2025 14:04
Copy link
Member

@efimov-mikhail efimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
I can confirm that issue with double generation of JIT stencils for PGO build is fixed.
And Makefile.pre.in changes looks clean for me.

@vstinner
Copy link
Member

vstinner commented Dec 9, 2025

I can confirm that issue with double generation of JIT stencils for PGO build is fixed.

I also confirm that the change works as expected.

I built Python with the JIT and PGO using commands:

./configure --enable-experimental-jit=yes --enable-optimizations
make clean
make

Currently, I see the command twice in make logs:

python3.15 ./Tools/jit/build.py x86_64-pc-linux-gnu --output-dir . --pyconfig-dir . --cflags="" --llvm-version=""

With this PR, I only see the command once.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vstinner vstinner merged commit 8914148 into python:main Dec 9, 2025
48 checks passed
@hroncok hroncok deleted the nocleanjit branch December 9, 2025 12:44
@vstinner
Copy link
Member

vstinner commented Dec 9, 2025

Merged, thanks!

The question is now if this change should be backported to 3.13 and 3.14 branches. Other branches are also affected by the issue, no? What do you think?

@merwok
Copy link
Member

merwok commented Dec 9, 2025

I would say yes to backport, as this is a build change and more a fix for specific needs than a new feature.

Pinging RM @hugovk

@hroncok
Copy link
Contributor Author

hroncok commented Dec 9, 2025

Merged, thanks!

The question is now if this change should be backported to 3.13 and 3.14 branches. Other branches are also affected by the issue, no? What do you think?

The other branches have the rm without the asterisk:

-rm -f jit_stencils.h

So technically, I am not even sure this is needed. I do not need a backport of this for Fedora.

@vstinner
Copy link
Member

@hroncok:

So technically, I am not even sure this is needed.

At least, I can say that make runs ./Tools/jit/build.py twice when building with PGO.

@hroncok
Copy link
Contributor Author

hroncok commented Dec 10, 2025

It runs twice but should only actually build the stencils once, due to the digest-match check.

@hugovk
Copy link
Member

hugovk commented Dec 11, 2025

I would say yes to backport, as this is a build change and more a fix for specific needs than a new feature.

Pinging RM @hugovk

Yep, looks like a backportable bug fix to me.

@efimov-mikhail efimov-mikhail added the needs backport to 3.14 bugs and security fixes label Dec 12, 2025
@miss-islington-app
Copy link

Thanks @hroncok for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @hroncok and @vstinner, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 8914148151c957aebfaab1f3c890144d1b33968d 3.14

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

Labels

needs backport to 3.14 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants