Skip to content

Commit a19b9da

Browse files
authored
Only enable line tracing when building with Cython tracing (#660)
1 parent 8c9d264 commit a19b9da

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

CHANGES/660.packaging.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fixed an issue where ``frozenlist`` binary wheels would be built with debugging symbols and line tracing enabled, which significantly impacted performance. Line tracing is now disabled by default and can only be enabled explicitly -- by :user:`bdraco`.
2+
3+
This change ensures that production builds are optimized for performance. Developers who need line tracing for debugging purposes can still enable it by:
4+
5+
1. Setting the ``FROZENLIST_CYTHON_TRACING`` environment variable
6+
2. Using the ``--config-setting=with-cython-tracing=true`` option with pip

packaging/pep517_backend/_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def maybe_prebuild_c_extensions(
291291
with build_dir_ctx:
292292
config = _get_local_cython_config()
293293

294-
cythonize_args = _make_cythonize_cli_args_from_config(config)
294+
cythonize_args = _make_cythonize_cli_args_from_config(config, cython_line_tracing_requested)
295295
with _patched_cython_env(config['env'], cython_line_tracing_requested):
296296
_cythonize_cli_cmd(cythonize_args)
297297
with patched_distutils_cmd_install():

packaging/pep517_backend/_cython_configuration.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,20 @@
1717
class Config(TypedDict):
1818
env: dict[str, str]
1919
flags: dict[str, bool]
20-
kwargs: dict[str, str]
20+
kwargs: dict[str, str | dict[str, str]]
2121
src: list[str]
2222

2323

24+
def _configure_cython_line_tracing(config_kwargs: dict[str, str | dict[str, str]], cython_line_tracing_requested: bool) -> None:
25+
"""Configure Cython line tracing directives if requested."""
26+
# If line tracing is requested, add it to the directives
27+
if cython_line_tracing_requested:
28+
directives = config_kwargs.setdefault('directive', {})
29+
assert isinstance(directives, dict) # Type narrowing for mypy
30+
directives['linetrace'] = 'True'
31+
directives['profile'] = 'True'
32+
33+
2434
def get_local_cython_config() -> Config:
2535
"""Grab optional build dependencies from pyproject.toml config.
2636
@@ -78,11 +88,15 @@ def get_local_cython_config() -> Config:
7888
return config_mapping['tool']['local']['cythonize'] # type: ignore[no-any-return]
7989

8090

81-
def make_cythonize_cli_args_from_config(config: Config) -> list[str]:
91+
def make_cythonize_cli_args_from_config(config: Config, cython_line_tracing_requested: bool = False) -> list[str]:
8292
py_ver_arg = f'-{_python_version_tuple.major!s}'
8393

8494
cli_flags = get_enabled_cli_flags_from_config(config['flags'])
85-
cli_kwargs = get_cli_kwargs_from_config(config['kwargs'])
95+
96+
config_kwargs = config['kwargs']
97+
_configure_cython_line_tracing(config_kwargs, cython_line_tracing_requested)
98+
99+
cli_kwargs = get_cli_kwargs_from_config(config_kwargs)
86100

87101
return cli_flags + [py_ver_arg] + cli_kwargs + ['--'] + config['src']
88102

packaging/pep517_backend/_transformers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def _emit_opt_pairs(opt_pair: Tuple[str, Union[str, Dict[str, str]]]) -> Iterato
1616
yield from ("=".join(map(str, (flag_opt,) + pair)) for pair in sub_pairs)
1717

1818

19-
def get_cli_kwargs_from_config(kwargs_map: Mapping[str, str]) -> List[str]:
19+
def get_cli_kwargs_from_config(
20+
kwargs_map: Mapping[str, Union[str, Dict[str, str]]],
21+
) -> List[str]:
2022
"""Make a list of options with values from config."""
2123
return list(chain.from_iterable(map(_emit_opt_pairs, kwargs_map.items())))
2224

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ keep-going = false
4848
# https://cython.rtfd.io/en/latest/src/userguide/source_files_and_compilation.html#compiler-directives
4949
embedsignature = "True"
5050
emit_code_comments = "True"
51-
linetrace = "True" # Implies `profile=True`
5251

5352
[tool.local.cythonize.kwargs.compile-time-env]
5453
# This section can contain compile time env vars

0 commit comments

Comments
 (0)