Skip to content

feat(hooks): declare native extension free-thread safe#120

Merged
art049 merged 1 commit into
masterfrom
feat/declare-free-threaded-safe
May 12, 2026
Merged

feat(hooks): declare native extension free-thread safe#120
art049 merged 1 commit into
masterfrom
feat/declare-free-threaded-safe

Conversation

@art049
Copy link
Copy Markdown
Member

@art049 art049 commented May 12, 2026

Declare the dist_instrument_hooks native extension as supporting the
free-threaded build, silencing the runtime warning emitted when the module is
imported on a free-threaded interpreter (e.g. 3.13t/3.14t/3.15t).

Without this declaration, CPython re-enables the GIL on import and prints:

RuntimeWarning: The global interpreter lock (GIL) has been enabled to load
module 'pytest_codspeed.instruments.hooks.dist_instrument_hooks', which has
not declared that it can run safely without the GIL.

The underlying instrument-hooks C library uses its own internal locking
(os_unfair_lock / mutex), so the module is safe to run without the GIL. The
PyUnstable_Module_SetGIL call is guarded by #ifdef Py_GIL_DISABLED so it has
no effect on standard (GIL-enabled) builds.

Declare the dist_instrument_hooks module as supporting the free-threaded
build by calling PyUnstable_Module_SetGIL(Py_MOD_GIL_NOT_USED) under
Py_GIL_DISABLED. Without this, importing the extension on a free-threaded
interpreter re-enables the GIL and emits a RuntimeWarning. The underlying
instrument-hooks C library uses its own internal locking, so the module
is safe to run without the GIL.

Co-Authored-By: Claude <noreply@anthropic.com>
@art049 art049 merged commit fda1fbc into master May 12, 2026
52 of 53 checks passed
@art049 art049 deleted the feat/declare-free-threaded-safe branch May 12, 2026 23:37
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 12, 2026

Merging this PR will degrade performance by 22.9%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 20 improved benchmarks
❌ 23 regressed benchmarks
✅ 234 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_multiprocessing_map[10000] 92.7 ms 105.5 ms -12.16%
WallTime test_generate_all_combinations[5-4] 10.1 µs 10.4 µs -3.61%
WallTime test_sudoku[initial_grid0] 8.1 µs 7.9 µs +2.14%
WallTime test_fs_write[10000] 43.8 µs 42.6 µs +2.81%
WallTime test_sum_of_squares[sum_of_squares_sum_comprehension_product] 194.2 µs 213.5 µs -9.03%
WallTime test_hostname_resolution[localhost] 124.4 µs 118.4 µs +5.05%
WallTime test_process_creation[cat /dev/null] 5.5 ms 5.4 ms +2.09%
WallTime test_pipe_communication[10000] 13.8 ms 14.5 ms -5.04%
WallTime test_recursive_fibo_20 5.5 ms 5.7 ms -3.64%
WallTime test_multiprocessing_map[1000] 60.9 ms 59 ms +3.17%
WallTime test_combination_sum[candidates0-8] 11.6 µs 12.1 µs -4.08%
WallTime test_open_knight_tour[1] 4.2 µs 4.6 µs -8.2%
WallTime test_noop_lambda_decorated 1.2 µs 1.3 µs -10.06%
WallTime test_fs_write[1000] 17.9 µs 17.1 µs +4.35%
WallTime test_tcp_connection[1.1.1.1-53] 981.4 µs 943.2 µs +4.05%
WallTime test_mmap_operation[409600] 133.8 µs 136.9 µs -2.22%
WallTime test_threadpool_map[10000] 375.6 ms 384.3 ms -2.26%
WallTime test_sum_of_squares[sum_of_squares_for_loop_power] 191.5 µs 184.9 µs +3.61%
WallTime test_sum_of_squares[sum_of_squares_sum_comprehension_power] 238.8 µs 220.5 µs +8.32%
WallTime test_multiprocessing_map[100000] 133.8 ms 160.4 ms -16.59%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/declare-free-threaded-safe (1c90271) with master (f3ed388)

Open in CodSpeed

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