[Python-Dev] Building a Faster Python

Ned Deily nad at acm.org
Mon Jul 22 02:32:51 CEST 2013


In article <252C50D8-C23D-438D-BAE1-B22E0D65A21A at gmail.com>,
 Raymond Hettinger <raymond.hettinger at gmail.com> wrote:
> Our current Mac OS X builds use GCC-4.2.
> 
> On Python2.7, I ran a comparison of gcc-4.2.1 builds
> versus gcc-4.8.1 and found that the latter makes a much
> faster Python.  PyBench2.0 shows the total running time
> dropping from 5653ms to 4571ms.  The code is uniformly
> better in just about every category.

Interesting.  A note about compilers:  it looks like the benchmark used 
the Apple gcc4.2-frontend / LLVM-backend hybrid compiler that is shipped 
with Xcode 4.  We don't use that compiler for building any OS X binary 
installers, in fact, we blacklist it for Python 3.3+ because we couldn't 
get it to produce a working 3.3 interpreter:

   http://bugs.python.org/issue13241

Apple has deprecated use of that compiler (it hasn't been patched in 
ages) and has announced that it will no longer be shipped starting with 
the next major release of Xcode, which is expected with the upcoming 
release of OS X 10.9 (Mavericks).

What would be interesting is to run the benchmark with Apple's currently 
supported compiler for OS X, clang, which is the default "cc" in the 
most recent versions of Xcode 4 (4.6.3) for OS X 10.7 and 10.8.

  $ cc --version
  Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)

Clang is expected to be the only compiler available via Xcode for 10.9.  
Note that the most recent Python binary installers default to using 
clang to build user extension modules with Xcode 4 on 10.7 and 10.8.

Currently, for the Intel-only (64-bit/32-bit) installers we instead use 
the final Apple-supplied gcc-4.2 (gcc front- and backend, no LLVM) 
shipped with Xcode 3.2.6 on OS X 10.6:
   [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin]
This makes it easier to provide one Python that can be installed and 
works on multiple OS X versions, for the Intel-only variant: 10.6 
through 10.8.  As of Xcode 4, Apple no longer ships this compiler.  
Because of the post-4.2 switch to GPL-3 licensing for gcc, it seems that 
Apple has no plans to look at, much less ship, anything newer than 4.2 
from the gcc code base.  At some point, we will probably switch to using 
clang for the Python in the installer but, at the moment, there appear 
to still be a large number of systems out there running OS X 10.6.

(Also, we and most third-party open-source package managers, like 
MacPorts and Homebrew, stick to using Apple-supplied compilers for most 
things rather than vanilla Gnu gcc 4.x because, among other things, 
Apple includes additional support within their compiler build chain for 
features like universal binaries and SDK support.)

-- 
 Ned Deily,
 nad at acm.org



More information about the Python-Dev mailing list