Skip to content

.github: build the Linux extension with Python's compile flags - #798

Open
mario4tier wants to merge 1 commit into
devfrom
linux-wheel-flags
Open

mario4tier wants to merge 1 commit into
devfrom
linux-wheel-flags

Conversation

@mario4tier

Copy link
Copy Markdown
Member

Since 0.7.1 the Linux jobs set CFLAGS=-D_GNU_SOURCE. setuptools uses an environment CFLAGS in place of Python's own compile flags, so the Cython extension in the Linux wheels is compiled without optimisation:

0.8.3.post1: gcc -pthread -D_GNU_SOURCE -fPIC ... -c talib/_ta_lib.c
this PR:     gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC ... -c talib/_ta_lib.c

Only the wrapper code is affected: the C library inside the wheel is already built at -O3, and the macOS and Windows jobs never set CFLAGS. _GNU_SOURCE was for the C library's tools, which setup.py no longer builds.

Time per call on an i7-13700K, two CPython 3.12 manylinux wheels built from the same source with and without the CFLAGS setting (pinned core, best of 6 alternating runs):

call with CFLAGS this PR
SMA, 100 bars 411 ns 287 ns 30% faster
SMA, 1,000 bars 1110 ns 998 ns 10% faster
SMA, 100,000 bars 76040 ns 76025 ns same
RSI, 100 bars 537 ns 421 ns 22% faster
BBANDS, 100 bars 749 ns 594 ns 21% faster
MACD, 1,000 bars 1444 ns 1289 ns 11% faster
stream.SMA, 100 bars 437 ns 284 ns 35% faster
abstract.Function('SMA')(inputs), 100 bars 5345 ns 2714 ns 49% faster
abstract.Function('SMA') 11708 ns 6418 ns 45% faster

The gain is in the per-call overhead, so it fades as the series grows. A Ryzen 7 PRO 8840U shows the same direction.

The cost is build time: the Linux jobs took 82 min (x86_64) and 105 min (arm64) in the test run, against 43 and 44 min for 0.8.3.post1. Python's flags include -g, so the wheels are repaired with auditwheel repair --strip, which removes the debug info and the symbol table (cp312 manylinux x86_64: 5.0 MB today, 4.6 MB with this PR).

Tested with a full wheels.yml run on master plus this PR and #797.

The Linux jobs exported CFLAGS=-D_GNU_SOURCE. setuptools uses an
environment CFLAGS in place of the interpreter's own, so the Cython
extension was compiled without -O3 and -DNDEBUG. The TA-Lib C library
inside the wheel was not affected: CMake builds it Release.

Remove the setting. It was added for the 0.7.1 build of the C library's
tools, which setup.py no longer builds, and Python.h defines _GNU_SOURCE
for the extension itself.

Python's flags include -g, so strip the repaired wheels to keep their
size.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant