Skip to content

Commit

Permalink
Optimize python with LTO & no-semantic (#82)
Browse files Browse the repository at this point in the history
* Optimize python with LTO & no-semantic

* Change optimize

* align patch also to 3.7
  • Loading branch information
pvizeli authored Jul 10, 2020
1 parent 901620d commit 24f3e8a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 6 deletions.
6 changes: 4 additions & 2 deletions python/3.6/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN set -ex \
dpkg-dev dpkg \
expat-dev \
findutils \
gcc \
build-base \
gdbm-dev \
libc-dev \
libffi-dev \
Expand Down Expand Up @@ -73,14 +73,16 @@ RUN set -ex \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-shared \
--with-lto \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& make -j "$(nproc)" \
LDFLAGS="-Wl,--strip-all" \
CFLAGS="-fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc" \
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
LDFLAGS="-Wl,--strip-all" \
# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044
PROFILE_TASK='-m test.regrtest --pgo \
test_asyncio \
Expand Down
6 changes: 4 additions & 2 deletions python/3.7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN set -ex \
dpkg-dev dpkg \
expat-dev \
findutils \
gcc \
build-base \
gdbm-dev \
libc-dev \
libffi-dev \
Expand Down Expand Up @@ -73,14 +73,16 @@ RUN set -ex \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-shared \
--with-lto \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& make -j "$(nproc)" \
LDFLAGS="-Wl,--strip-all" \
CFLAGS="-fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc" \
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
LDFLAGS="-Wl,--strip-all" \
# setting PROFILE_TASK makes "--enable-optimizations" reasonable: https://bugs.python.org/issue36044
PROFILE_TASK='-m test.regrtest --pgo \
test_asyncio \
Expand Down
17 changes: 17 additions & 0 deletions python/3.7/arm-alignment.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Author: Dave Jones <[email protected]>
Description: Use aligned access for _sha3 module on ARM.
--- a/Modules/_sha3/sha3module.c
+++ b/Modules/_sha3/sha3module.c
@@ -64,6 +64,12 @@
#define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
#endif

+/* Bus error on 32-bit ARM due to un-aligned memory accesses; 64-bit ARM
+ * doesn't complain but un-aligned memory accesses are sub-optimal */
+#if defined(__arm__) || defined(__aarch64__)
+#define NO_MISALIGNED_ACCESSES
+#endif
+
/* mangle names */
#define KeccakF1600_FastLoop_Absorb _PySHA3_KeccakF1600_FastLoop_Absorb
#define Keccak_HashFinal _PySHA3_Keccak_HashFinal
6 changes: 4 additions & 2 deletions python/3.8/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ RUN set -ex \
dpkg-dev dpkg \
expat-dev \
findutils \
gcc \
build-base \
gdbm-dev \
libc-dev \
libffi-dev \
Expand Down Expand Up @@ -73,14 +73,16 @@ RUN set -ex \
--enable-loadable-sqlite-extensions \
--enable-optimizations \
--enable-shared \
--with-lto \
--with-system-expat \
--with-system-ffi \
--without-ensurepip \
&& make -j "$(nproc)" \
LDFLAGS="-Wl,--strip-all" \
CFLAGS="-fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc" \
# set thread stack size to 1MB so we don't segfault before we hit sys.getrecursionlimit()
# https://github.com/alpinelinux/aports/commit/2026e1259422d4e0cf92391ca2d3844356c649d0
EXTRA_CFLAGS="-DTHREAD_STACK_SIZE=0x100000" \
LDFLAGS="-Wl,--strip-all" \
&& make install \
\
&& find /usr/local -type f -executable -not \( -name '*tkinter*' \) -exec scanelf --needed --nobanner --format '%n#p' '{}' ';' \
Expand Down
17 changes: 17 additions & 0 deletions python/3.8/arm-alignment.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Author: Dave Jones <[email protected]>
Description: Use aligned access for _sha3 module on ARM.
--- a/Modules/_sha3/sha3module.c
+++ b/Modules/_sha3/sha3module.c
@@ -64,6 +64,12 @@
#define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
#endif

+/* Bus error on 32-bit ARM due to un-aligned memory accesses; 64-bit ARM
+ * doesn't complain but un-aligned memory accesses are sub-optimal */
+#if defined(__arm__) || defined(__aarch64__)
+#define NO_MISALIGNED_ACCESSES
+#endif
+
/* mangle names */
#define KeccakF1600_FastLoop_Absorb _PySHA3_KeccakF1600_FastLoop_Absorb
#define Keccak_HashFinal _PySHA3_Keccak_HashFinal

0 comments on commit 24f3e8a

Please sign in to comment.