python2: use PGO on the interpreter
This CL turns on PGO for all builds of Python's interpreter.
Python appears to have support for some of this on its own, though:
- that support appears to be confined to GCC in Python2 (Python3 grew
support for clang at some point)
- for reasons detailed below, we don't want to generate a new profile on
every `emerge` of Python
...So none of that is really useful to us in Python2.
PGO increases the installed tree size by 8KB, so size isn't an issue
here.
Experimentally, PGO makes Python-heavy operations (such as `equery b
/path/to/foo`) consume 8% fewer user cycles than builds without PGO.
Due to issues with LTO, a comment was added about it, but it wasn't
enabled.
This also includes a script that can be used to generate new profiles.
Since profile generation is nondeterministic, and since it takes
O(minutes), we don't regenerate profiles on each run of the ebuild.
Given the scary comment at the top of python's ebuild, I added a nop
change to dev-install so it's hopefully uprevved.
BUG=None
TEST=emerged the PGO'ed python, built {falco,bob,daisy} from the ground
up with it.
Change-Id: Idfaf79099f72ad82b0c1c092481da62793adb21d
Reviewed-on: https://chromium-review.googlesource.com/1455417
Commit-Ready: George Burgess <gbiv@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/dev-lang/python/files/python-2.7-clear-extra-cflags.patch b/dev-lang/python/files/python-2.7-clear-extra-cflags.patch
new file mode 100644
index 0000000..e37b516
--- /dev/null
+++ b/dev-lang/python/files/python-2.7-clear-extra-cflags.patch
@@ -0,0 +1,26 @@
+Python uses a hand-rolled Makefile parser to pick out important build-related
+environment variables and stash them in the `sysconfig` module. Crucially, it'll
+take a Makefile that looks like
+
+```
+FOO = 1
+BAR = $(FOO) $(BAZ) $(QUX)
+```
+
+...And given an environment of {'FOO': 99, 'BAZ': '98'}, will produce something
+like {'FOO': '1', 'BAR': '1 98 '}
+
+Since EXTRA_CFLAGS is literally only used as a means to pass a PGO profile in,
+and that profile won't be available to anything but the core Python modules, we
+clear EXTRA_CFLAGS for the generation of sysconfig.
+
+--- a/Makefile.pre.in
++++ b/Makefile.pre.in
+@@ -456,6 +456,7 @@ platform: $(BUILDPYTHON) pybuilddir.txt
+ # or removed in case of failure.
+ pybuilddir.txt: $(BUILDPYTHON)
+ @echo "none" > ./pybuilddir.txt
++ EXTRA_CFLAGS= \
+ $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars ;\
+ if test $$? -ne 0 ; then \
+ echo "generate-posix-vars failed" ; \