Skip to content

perf(python): release the GIL once per scan export - #10497

Open
robert3005 wants to merge 3 commits into
rk/python-codspeedfrom
rk/python-gil
Open

robert3005 wants to merge 3 commits into
rk/python-codspeedfrom
rk/python-gil

Conversation

@robert3005

@robert3005 robert3005 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Scans that export to Arrow from Python release the GIL fewer times. When other threads hold the GIL, each release costs a wait to take it back.

@codspeed

codspeed Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 38.33%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ 1 benchmark measured no execution time

Nothing ran under measurement, usually because the compiler removed the code under test. This result is not comparable, so it counts as unchanged.

Preventing compiler optimizations

⚠️ 17 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

⚠️ 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

⚡ 15 improved benchmarks
❌ 6 regressed benchmarks
✅ 2222 untouched benchmarks
🆕 16 new benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation i64_random_chunked[256] 226.6 µs 13,908.3 µs -98.37%
❌ Simulation utf8_random[256] 416.6 µs 12,969.1 µs -96.79%
❌ Simulation i64_random[256] 170.2 µs 3,941.4 µs -95.68%
❌ Simulation nested_list_random[32] 1 ms 6.7 ms -84.48%
❌ ⚠️ Simulation density_sweep_dense_runs[0.001] 28.7 µs 47.6 µs -39.8%
❌ WallTime threshold_avx2[8] 1.9 µs 2.2 µs -14.16%
⚡ Simulation optimize_lookup_predicate[ids=192, shape=in_list] 76.4 µs 51 µs +49.81%
⚡ Simulation optimize_lookup_predicate[ids=128, shape=in_list] 73.8 µs 51.7 µs +42.76%
⚡ Simulation optimize_lookup_predicate[ids=64, shape=in_list] 71.2 µs 51.5 µs +38.15%
⚡ Simulation optimize_lookup_predicate[ids=16, shape=in_list] 70 µs 52.4 µs +33.66%
⚡ Simulation optimize_lookup_predicate[ids=256, shape=in_list] 105.9 µs 79.6 µs +32.93%
⚡ WallTime threshold_neon[8] 3.6 µs 2.9 µs +23.65%
⚡ Simulation optimize_lookup_predicate[ids=1, shape=in_list] 90.5 µs 75.3 µs +20.26%
⚡ Simulation sum_v2_i64 224.8 µs 194.5 µs +15.6%
⚡ Simulation sum_i64 224.6 µs 194.4 µs +15.55%
⚡ Simulation random_i8[0.01] 124.1 µs 108.6 µs +14.29%
⚡ WallTime starts_with_avx512[8, VarBin] 46.4 µs 40.7 µs +14.19%
⚡ Simulation test_scan_filter[int] 3.5 ms 3.1 ms +13.44%
⚡ WallTime filter_neon[80] 3.5 µs 3.1 µs +13.02%
⚡ ⚠️ Simulation random_i128[0.01] 8.1 µs 7.2 µs +11.68%
... ... ... ... ... ...

ℹ️ 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 rk/python-gil (40cfa27) with rk/python-codspeed (029e60c)1

Open in CodSpeed

Footnotes

  1. No successful run was found on rk/python-codspeed (a135e85) during the generation of this report, so 8bdcedc was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@robert3005 robert3005 added the changelog/feature A new feature label Oct 14, 2026
@joseph-isaacs

Copy link
Copy Markdown
Contributor

Shall we add py benchmarks?

@robert3005
robert3005 changed the base branch from develop to rk/python-codspeed October 14, 2026 18:33
@robert3005
robert3005 force-pushed the rk/python-gil branch 2 times, most recently from 29bdc1a to b161762 Compare October 14, 2026 21:02
robert3005 and others added 2 commits October 14, 2026 22:15
ArrayIterator.to_arrow_array reads and exports to Arrow in one GIL release,
rather than one for read_all and one for Array.to_arrow_array. Short row
index lists are decoded with the GIL held.

Signed-off-by: Robert Kruszewski <github@robertk.io>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Benchmark the single-GIL-release export for scans, repeated scans and
filtered scans, with the read_all().to_arrow_array() path as a baseline.

Signed-off-by: Robert Kruszewski <github@robertk.io>

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants