Subject: bug#47251: closed (Re: bug#47251: [core-updates] [patch] gnu: python: Enable optimizations.)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 11 Jun 2021 01:04:01 +0000

Your bug report

#47251: [core-updates] [patch] gnu: python: Enable optimizations.

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
47251: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=47251
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#47251: [core-updates] [patch] gnu: python: Enable optimizations.
From: Julien Lepiller <[email-masked]>
To: Ludovic Courtès <[email-masked]>
Cc: [email-masked]
Date: Fri, 11 Jun 2021 03:03:33 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Le Sun, 06 Jun 2021 14:34:31 +0200,
Ludovic Courtès <[email-masked]> a écrit :

> 
> > +             "CFLAGS=-fno-semantic-interposition"
> >               (string-append "LDFLAGS=-Wl,-rpath="
> > -                            (assoc-ref %outputs "out") "/lib"))
> > +                            (assoc-ref %outputs "out") "/lib"
> > +                            " -fno-semantic-interposition"))  
> 
> Could you add a comment for ‘-fno-semantic-interposition’?  Also,
> please make sure that setting CFLAGS does not override useful
> defaults (for Autoconf-based build systems, CFLAGS defaults to ‘-O2
> -g’ and overriding it means you lost both -O2 and -g; if we lose
> ‘-g’, ‘--with-debug-info’ won’t have any effect).
> 

With the patch, python still builds with -g -O3.

Pushed as 99d450b085b7bf44d669093f6c9964391ce1b451 to
e4aa346d57f61956626032d0d1dfca6b3c96e06a to core-updates, thanks!

Subject: [core-updates] [patch] gnu: python: Enable optimizations.
From: Julien Lepiller <[email-masked]>
To: [email-masked]
Date: Fri, 19 Mar 2021 00:16:22 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi Guix!

This is the second patch I created in my exploration of our Python
package. Here, I noticed that our Python was very slow compared to
other distros and I tried to find which options they used. I found some
hints from Fedora. In this patch, I enable a few options and add a C/LD
flag to make python run faster.

I also attached a report of timing running the benchmark from
pyperformance on my Fedora machine. For comparison, I have also added
the results for Fedora's python3, which is somewhere in between.

I noticed that this increases the size of the python package by 20MB,
which is due entirely to --with-lto option, which also accounts for
half of the speedup. Overall, this python is almost twice as fast on
some benchmarks, and always faster on all of them. It's about 1.5 times
faster on average.

Strangely, the python package from Alpine is twice as small as this
package, and they use the --with-lto option. I wonder how they achieve
that.

Note that I modified python-2, as its flags are inherited by python-3
(and also the bootstrap python from commencement.scm).
>From c72e34aa0eb0db589557e047c5db0128273d5d12 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <[email-masked]>
Date: Thu, 18 Mar 2021 23:41:40 +0100
Subject: [PATCH 2/2] gnu: python: Enable optimizations.

As a result, python execution time of scripts is decreased by 6 to 40%.

gnu/packages/python (python-2.7)[arguments]: Add configure and make flags to
optimize the resulting python.
---
 gnu/packages/python.scm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/python.scm b/gnu/packages/python.scm
index da9859b11a..8de0ca343c 100644
--- a/gnu/packages/python.scm
+++ b/gnu/packages/python.scm
@@ -183,7 +183,10 @@
              "--with-system-expat"      ;for XML support
              "--with-system-ffi"        ;build ctypes
              "--with-ensurepip=install" ;install pip and setuptools
+             "--with-computed-gotos"    ;main interpreter loop optimization
+             "--with-lto"               ;increase size by 20MB, but 15% speedup
              "--enable-unicode=ucs4"
+             "--enable-optimizations"
 
              ;; Prevent the installed _sysconfigdata.py from retaining a reference
              ;; to coreutils.
@@ -197,8 +200,10 @@
                      "ac_cv_file__dev_ptmx=no"
                      "ac_cv_file__dev_ptc=no")
                    '())
+             "CFLAGS=-fno-semantic-interposition"
              (string-append "LDFLAGS=-Wl,-rpath="
-                            (assoc-ref %outputs "out") "/lib"))
+                            (assoc-ref %outputs "out") "/lib"
+                            " -fno-semantic-interposition"))
        ;; With no -j argument tests use all available cpus, so provide one.
        #:make-flags
        (list (string-append
-- 
2.30.0