pytest-codspeed icon indicating copy to clipboard operation
pytest-codspeed copied to clipboard

Remove CFFI in favor of native extension to support free-threaded mode

Open adriencaccia opened this issue 1 month ago • 4 comments

Fix #86

This is still a work in progress, it must be tested thoroughly in CI to ensure that it plays well with free-threaded versions of Python, using UV or not.

adriencaccia avatar Oct 28 '25 15:10 adriencaccia

CodSpeed Performance Report

Merging #96 will degrade performances by 24.69%

Comparing feat/remove-cffi (411adc2) with master (adee8a1)

Summary

⚡ 47 improvements
❌ 22 regressions
✅ 98 untouched

:warning: Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Mode Benchmark BASE HEAD Change
Simulation test_iir_filter_process 35.2 µs 32.8 µs +7.29%
WallTime test_iir_filter_process 2.6 µs 2.7 µs -3.85%
Simulation test_iir_filter_set_coefficients[a_coeffs0-b_coeffs0] 16.7 µs 14 µs +19.03%
Simulation test_make_allpass 46.4 µs 43.8 µs +5.99%
Simulation test_make_bandpass 47.1 µs 44.5 µs +5.93%
Simulation test_make_highpass 47.2 µs 44.5 µs +6.13%
Simulation test_make_highshelf 46.1 µs 43.6 µs +5.72%
Simulation test_make_lowpass 47 µs 44.5 µs +5.81%
WallTime test_make_lowpass 5.3 µs 5.5 µs -2.81%
Simulation test_make_lowshelf 46.1 µs 43.6 µs +5.8%
WallTime test_make_lowshelf 7.4 µs 7.2 µs +3.3%
WallTime test_make_peak 6 µs 6.2 µs -2.73%
Simulation test_make_peak 43.3 µs 40.9 µs +5.9%
Simulation test_color[graph0-3] 76.7 µs 74 µs +3.68%
Simulation test_combination_lists[0-0] 26.5 µs 23.9 µs +10.78%
Simulation test_combination_lists[4-2] 31.3 µs 28.7 µs +8.81%
Simulation test_combination_lists[5-4] 31.4 µs 28.9 µs +8.65%
WallTime test_combination_sum[candidates0-8] 10.9 µs 11.1 µs -2.62%
Simulation test_combination_sum[candidates0-8] 43.6 µs 40.9 µs +6.61%
Simulation test_depth_first_search[4] 86.2 µs 84.2 µs +2.34%
... ... ... ... ... ...

:information_source: Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

codspeed-hq[bot] avatar Oct 28 '25 15:10 codspeed-hq[bot]

Fix #86

This is still a work in progress, it must be tested thoroughly in CI to ensure that it plays well with free-threaded versions of Python, using UV or not.

Sounds good. I can't wait to see if this will pass on through or not.

Vizonex avatar Oct 29 '25 21:10 Vizonex

Sounds good. I can't wait to see if this will pass on through or not.

It seems that there is an issue when running CODSPEED_LOG=debug codspeed --mode instrumentation -- uv run pytest tests/ --codspeed with python3.14t Here is the error:

Fatal Python error:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                      
preconfig_init_allocator:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                
PYTHONMALLOC: unknown allocator
Python runtime state:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                    
preinitializing  ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                           


Stack (most recent call first):
  <tstate is freed>

In the runner we are setting the following: https://github.com/CodSpeedHQ/runner/blob/e89b00befed092f3300c89b9f6577a00e025c944/src/run/runner/valgrind/measure.rs#L91

Do you know if there is any issue with free-threaded python and using PYTHONMALLOC?

adriencaccia avatar Oct 30 '25 09:10 adriencaccia

Sounds good. I can't wait to see if this will pass on through or not.

It seems that there is an issue when running CODSPEED_LOG=debug codspeed --mode instrumentation -- uv run pytest tests/ --codspeed with python3.14t Here is the error:

Fatal Python error:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                      
preconfig_init_allocator:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                
PYTHONMALLOC: unknown allocator
Python runtime state:   ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                    
preinitializing  ⠠ Running the benchmarks...                                                                                                                                                                                                                                                                           


Stack (most recent call first):
  <tstate is freed>

In the runner we are setting the following: https://github.com/CodSpeedHQ/runner/blob/e89b00befed092f3300c89b9f6577a00e025c944/src/run/runner/valgrind/measure.rs#L91

Do you know if there is any issue with free-threaded python and using PYTHONMALLOC?

@adriencaccia Sorry for my rather late response but there is one called PyMem_RawMalloc which can be ran without the gil same with PyMem_RawFree, PyMem_RawRealloc, PyMem_RawCalloc

Vizonex avatar Oct 30 '25 16:10 Vizonex