nixpkgs/pkgs/development/interpreters/python
Andreas Rammhold 322eb3596b cpython: add enableNoSemanticInterposition flag
This flags enables the -fno-semantic-interposition compiler flag for all
our cpython builds by default. It can be disabled by overriding the
enableNoSemanticInterposition attribute.

This CFLAG has the impact that our python code runs up to 23% faster
than previously. See the pyperformance benchmark results below.

The only downside that exists is that we can no longer override
libpython symbols via LD_PRELOAD when calling the python interpreter. If
a user needs they can disable the newly introduced flag and use that
instead. However those situations should be rare.

The Fedora Project did the equivalent change in their Fedora 32 release
(and haven't reverted it yet). They wrote a nice [wiki page] about the
ups and downs of this change. I recommend reading that.

Benchmark results of running Python 3.9 before and after this change:

+-------------------------+---------------+--------------------+--------------+------------------------+
| Benchmark               | py39.nix.json | py39-nsip.nix.json | Change       | Significance           |
+=========================+===============+====================+==============+========================+
| 2to3                    | 666 ms        | 642 ms             | 1.04x faster | Significant (t=12.73)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| chameleon               | 15.0 ms       | 14.6 ms            | 1.03x faster | Significant (t=4.70)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| chaos                   | 198 ms        | 182 ms             | 1.09x faster | Significant (t=13.73)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| crypto_pyaes            | 185 ms        | 175 ms             | 1.06x faster | Significant (t=9.70)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| deltablue               | 12.3 ms       | 11.2 ms            | 1.10x faster | Significant (t=14.45)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| django_template         | 85.1 ms       | 82.0 ms            | 1.04x faster | Significant (t=6.61)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| dulwich_log             | 102 ms        | 101 ms             | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| fannkuch                | 670 ms        | 634 ms             | 1.06x faster | Significant (t=15.87)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| float                   | 182 ms        | 176 ms             | 1.03x faster | Significant (t=7.32)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| go                      | 393 ms        | 366 ms             | 1.07x faster | Significant (t=17.63)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| hexiom                  | 15.8 ms       | 14.9 ms            | 1.06x faster | Significant (t=13.81)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| json_dumps              | 19.3 ms       | 18.7 ms            | 1.03x faster | Significant (t=7.46)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| json_loads              | 38.4 us       | 37.9 us            | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| logging_format          | 15.0 us       | 14.2 us            | 1.05x faster | Significant (t=6.32)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| logging_silent          | 328 ns        | 305 ns             | 1.07x faster | Significant (t=8.85)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| logging_simple          | 13.8 us       | 13.0 us            | 1.06x faster | Significant (t=10.77)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| mako                    | 25.2 ms       | 24.7 ms            | 1.02x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| meteor_contest          | 133 ms        | 130 ms             | 1.03x faster | Significant (t=3.59)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| nbody                   | 222 ms        | 201 ms             | 1.10x faster | Significant (t=26.85)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| nqueens                 | 161 ms        | 152 ms             | 1.06x faster | Significant (t=8.84)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pathlib                 | 28.4 ms       | 26.3 ms            | 1.08x faster | Significant (t=11.85)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pickle                  | 13.8 us       | 13.1 us            | 1.06x faster | Significant (t=10.84)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pickle_dict             | 32.7 us       | 26.6 us            | 1.23x faster | Significant (t=32.43)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pickle_list             | 4.39 us       | 4.34 us            | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pickle_pure_python      | 782 us        | 738 us             | 1.06x faster | Significant (t=15.71)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pidigits                | 184 ms        | 181 ms             | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| pyflate                 | 1.02 sec      | 959 ms             | 1.07x faster | Significant (t=21.13)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| python_startup          | 34.3 ms       | 34.0 ms            | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| python_startup_no_site  | 15.5 ms       | 15.3 ms            | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| raytrace                | 912 ms        | 849 ms             | 1.07x faster | Significant (t=11.21)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| regex_compile           | 273 ms        | 261 ms             | 1.05x faster | Significant (t=5.82)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| regex_dna               | 188 ms        | 187 ms             | 1.00x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| regex_effbot            | 3.37 ms       | 3.66 ms            | 1.09x slower | Significant (t=-16.12) |
+-------------------------+---------------+--------------------+--------------+------------------------+
| regex_v8                | 29.8 ms       | 29.7 ms            | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| richards                | 119 ms        | 113 ms             | 1.05x faster | Significant (t=5.71)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| scimark_fft             | 625 ms        | 592 ms             | 1.06x faster | Significant (t=19.64)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| scimark_lu              | 273 ms        | 253 ms             | 1.08x faster | Significant (t=16.68)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| scimark_monte_carlo     | 186 ms        | 170 ms             | 1.10x faster | Significant (t=14.70)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| scimark_sor             | 330 ms        | 310 ms             | 1.07x faster | Significant (t=11.89)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| scimark_sparse_mat_mult | 9.03 ms       | 8.36 ms            | 1.08x faster | Significant (t=17.71)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| spectral_norm           | 247 ms        | 232 ms             | 1.06x faster | Significant (t=14.64)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sqlalchemy_declarative  | 194 ms        | 185 ms             | 1.04x faster | Significant (t=4.80)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sqlalchemy_imperative   | 28.2 ms       | 27.4 ms            | 1.03x faster | Significant (t=3.80)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sqlite_synth            | 4.89 us       | 4.73 us            | 1.03x faster | Significant (t=10.60)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sympy_expand            | 833 ms        | 813 ms             | 1.02x faster | Significant (t=4.82)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sympy_integrate         | 33.0 ms       | 31.6 ms            | 1.05x faster | Significant (t=6.47)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sympy_str               | 490 ms        | 477 ms             | 1.03x faster | Significant (t=7.58)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| sympy_sum               | 254 ms        | 245 ms             | 1.04x faster | Significant (t=7.82)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| telco                   | 11.6 ms       | 11.3 ms            | 1.03x faster | Significant (t=5.62)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| tornado_http            | 175 ms        | 172 ms             | 1.02x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| unpack_sequence         | 51.4 ns       | 56.2 ns            | 1.09x slower | Significant (t=-2.40)  |
+-------------------------+---------------+--------------------+--------------+------------------------+
| unpickle                | 20.3 us       | 19.8 us            | 1.02x faster | Significant (t=4.09)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| unpickle_list           | 5.41 us       | 5.75 us            | 1.06x slower | Significant (t=-26.56) |
+-------------------------+---------------+--------------------+--------------+------------------------+
| unpickle_pure_python    | 544 us        | 524 us             | 1.04x faster | Significant (t=6.47)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| xml_etree_generate      | 154 ms        | 148 ms             | 1.04x faster | Significant (t=7.98)   |
+-------------------------+---------------+--------------------+--------------+------------------------+
| xml_etree_iterparse     | 130 ms        | 129 ms             | 1.01x faster | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| xml_etree_parse         | 178 ms        | 179 ms             | 1.00x slower | Not significant        |
+-------------------------+---------------+--------------------+--------------+------------------------+
| xml_etree_process       | 123 ms        | 118 ms             | 1.04x faster | Significant (t=10.22)  |
+-------------------------+---------------+--------------------+--------------+------------------------+

[wiki page]: https://fedoraproject.org/wiki/Changes/PythonNoSemanticInterpositionSpeedup
2021-07-05 12:34:02 -07:00
..
catch_conflicts
conda Change all alsaLib references to alsa-lib 2021-06-10 01:12:49 -03:00
cpython cpython: add enableNoSemanticInterposition flag 2021-07-05 12:34:02 -07:00
graalpython pythonInterpreters.graalpython37: init 2019-10-22 09:16:18 +02:00
hooks python: pythonRemoveTestsDirHook removes /test 2021-06-21 16:48:39 -07:00
manylinux Fix manylinux packages 2019-12-13 11:40:44 +01:00
pypy lzma: deprecate alias 2021-04-04 19:49:52 +02:00
tests python.tests: use self.callPackage instead of super.callPackage 2020-11-28 16:57:07 +01:00
update-python-libraries update-python-libraries: handle github branches and tags with same name 2021-06-22 13:42:46 +02:00
default.nix python3: 3.8 -> 3.9 2021-07-05 12:34:02 -07:00
fetchpypi.nix python3Packages.fetchPypi: support wheels where dist & python differ 2021-06-22 13:42:45 +02:00
mk-python-derivation.nix pythonPackages: set mainProgram to pname by default 2021-06-12 23:23:35 +02:00
run_setup.py
setup-hook.nix
setup-hook.sh python: make it possible to disable the python setup-hook 2019-04-28 09:20:41 +02:00
sitecustomize.py Python: fix virtualenv with Python 2 2020-05-24 10:43:24 +02:00
tests.nix buildPythonPackage: add support for conda 2021-05-28 14:31:40 +02:00
with-packages.nix
wrap-python.nix Python: improve cross-compilation 2019-01-04 10:45:22 +01:00
wrap.sh python.pkgs.wrapPython: get rid of warning 2019-12-30 16:46:55 +01:00
wrapper.nix treewide: Fix various tools wrappers "with packages" 2021-03-02 22:38:04 +00:00