feat(hooks): declare native extension free-thread safe#120
Merged
Conversation
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>
Merging this PR will degrade performance by 22.9%
|
| 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Declare the
dist_instrument_hooksnative extension as supporting thefree-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:
The underlying
instrument-hooksC library uses its own internal locking(
os_unfair_lock/ mutex), so the module is safe to run without the GIL. ThePyUnstable_Module_SetGILcall is guarded by#ifdef Py_GIL_DISABLEDso it hasno effect on standard (GIL-enabled) builds.