Skip to content

Commit

Permalink
Turn off debug information in C extension
Browse files Browse the repository at this point in the history
Previously, pydantic used the default Python CFLAGS which include `-g`
(debug level 2). This is good for debugging at the C level, but it
significantly increases the size of the C extension shared library, and
is probably not needed by the vast majority of pydantic users. Thus, it
seems a better tradeoff to turn debug info off.

This can be overridden when building pydantic from source (not from PyPI
wheel) by using `CFLAGS='-O3 -g'`.

This change reduces the pydantic binary on cp310-linux-x86_64 from 31MB
(12MB wheel) to 8.9MB (3MB wheel).

Fixes pydantic#2276
  • Loading branch information
bluetech committed Dec 21, 2022
1 parent dc33b47 commit 2b4145f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -84,7 +84,7 @@ def extra(self):
compiler_directives['linetrace'] = True
# Set CFLAG to all optimizations (-O3)
# Any additional CFLAGS will be appended. Only the last optimization flag will have effect
os.environ['CFLAGS'] = '-O3 ' + os.environ.get('CFLAGS', '')
os.environ['CFLAGS'] = '-O3 -g0' + os.environ.get('CFLAGS', '')
ext_modules = cythonize(
'pydantic/*.py',
exclude=['pydantic/generics.py'],
Expand Down

0 comments on commit 2b4145f

Please sign in to comment.