GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` by cmaloney · Pull Request #140128 · python/cpython

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 14, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Update bytearray to contain a bytes and provide a zero-copy path to "extract" the bytes. This allows making several code paths more efficient.

This does not move any codepaths to make use of this new API. The documentation changes include common code patterns which can be made more efficient with this API.


When just changing bytearray to contain bytes I ran pyperformance on a --with-lto --enable-optimizations --with-static-libpython build (results below) and don't see any major speedups or slowdowns with this; all seems to be in the noise of my machine (Generally changes under 5% or benchmarks that don't touch bytes/bytearray).

pyperformance compare main.json bytearray_bytes.json

main.json

Performance version: 1.11.0
Report on Linux-6.17.1-arch1-1-x86_64-with-glibc2.42
Number of logical CPUs: 32
Start date: 2025-10-14 00:55:52.519236
End date: 2025-10-14 02:23:01.308400

bytearray_bytes.json

Performance version: 1.11.0
Report on Linux-6.17.1-arch1-1-x86_64-with-glibc2.42
Number of logical CPUs: 32
Start date: 2025-10-13 23:22:29.928152
End date: 2025-10-14 00:49:34.467284

+----------------------------------+-----------+----------------------+--------------+------------------------+
| Benchmark                        | main.json | bytearray_bytes.json | Change       | Significance           |
+==================================+===========+======================+==============+========================+
| 2to3                             | 137 ms    | 136 ms               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_generators                 | 193 ms    | 195 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_cpu_io_mixed          | 285 ms    | 286 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_cpu_io_mixed_tg       | 289 ms    | 290 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager                 | 50.4 ms   | 51.5 ms              | 1.02x slower | Significant (t=-10.40) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_cpu_io_mixed    | 223 ms    | 225 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_cpu_io_mixed_tg | 263 ms    | 264 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_io              | 370 ms    | 372 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_io_tg           | 380 ms    | 384 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_memoization     | 125 ms    | 126 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_memoization_tg  | 161 ms    | 162 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_tg              | 125 ms    | 125 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_io                    | 366 ms    | 360 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_io_tg                 | 359 ms    | 361 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_memoization           | 177 ms    | 181 ms               | 1.02x slower | Significant (t=-9.20)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_memoization_tg        | 188 ms    | 189 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_none                  | 151 ms    | 151 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_none_tg               | 150 ms    | 151 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_tcp                      | 182 ms    | 161 ms               | 1.13x faster | Significant (t=32.85)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_tcp_ssl                  | 548 ms    | 553 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_websockets               | 342 ms    | 339 ms               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bench_mp_pool                    | 7.12 ms   | 7.08 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bench_thread_pool                | 818 us    | 819 us               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bpe_tokeniser                    | 2.10 sec  | 2.09 sec             | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| chaos                            | 27.9 ms   | 28.0 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| comprehensions                   | 7.45 us   | 7.24 us              | 1.03x faster | Significant (t=3.27)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| connected_components             | 308 ms    | 309 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| coroutines                       | 11.1 ms   | 11.2 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| coverage                         | 33.6 ms   | 34.1 ms              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| create_gc_cycles                 | 1.16 ms   | 1.16 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| crypto_pyaes                     | 37.1 ms   | 35.6 ms              | 1.04x faster | Significant (t=10.63)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| dask                             | 347 ms    | 351 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy                         | 118 us    | 117 us               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy_memo                    | 12.8 us   | 12.7 us              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy_reduce                  | 1.32 us   | 1.34 us              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deltablue                        | 1.65 ms   | 1.64 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| django_template                  | 17.9 ms   | 17.8 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| docutils                         | 1.19 sec  | 1.20 sec             | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| dulwich_log                      | 19.5 ms   | 19.7 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| fannkuch                         | 184 ms    | 181 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| float                            | 37.1 ms   | 36.7 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| gc_traversal                     | 3.04 ms   | 2.84 ms              | 1.07x faster | Significant (t=19.48)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| generators                       | 15.9 ms   | 15.3 ms              | 1.04x faster | Significant (t=7.03)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| genshi_text                      | 11.3 ms   | 11.2 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| genshi_xml                       | 25.5 ms   | 25.5 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| go                               | 57.6 ms   | 56.7 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| hexiom                           | 2.92 ms   | 2.88 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| html5lib                         | 26.0 ms   | 26.5 ms              | 1.02x slower | Significant (t=-9.20)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| json_dumps                       | 4.48 ms   | 4.44 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| json_loads                       | 11.7 us   | 11.7 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| k_core                           | 1.41 sec  | 1.42 sec             | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_format                   | 3.27 us   | 3.30 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_silent                   | 45.5 ns   | 45.8 ns              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_simple                   | 3.02 us   | 3.01 us              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| mako                             | 6.02 ms   | 6.03 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| many_optionals                   | 473 us    | 478 us               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| mdp                              | 587 ms    | 578 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| meteor_contest                   | 50.2 ms   | 50.5 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| nbody                            | 54.6 ms   | 52.4 ms              | 1.04x faster | Significant (t=10.72)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| nqueens                          | 41.7 ms   | 40.4 ms              | 1.03x faster | Significant (t=6.79)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pathlib                          | 9.77 ms   | 9.73 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle                           | 5.99 us   | 6.01 us              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_dict                      | 12.5 us   | 12.8 us              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_list                      | 1.98 us   | 1.96 us              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_pure_python               | 149 us    | 150 us               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pidigits                         | 111 ms    | 115 ms               | 1.03x slower | Significant (t=-18.53) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pprint_pformat                   | 737 ms    | 748 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pprint_safe_repr                 | 362 ms    | 369 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pyflate                          | 211 ms    | 205 ms               | 1.03x faster | Significant (t=7.43)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| python_startup                   | 7.88 ms   | 7.88 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| python_startup_no_site           | 4.72 ms   | 4.76 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| raytrace                         | 130 ms    | 128 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_compile                    | 50.0 ms   | 50.2 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_dna                        | 101 ms    | 103 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_effbot                     | 1.72 ms   | 1.77 ms              | 1.03x slower | Significant (t=-26.42) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_v8                         | 12.5 ms   | 12.3 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| richards                         | 20.4 ms   | 20.0 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| richards_super                   | 23.4 ms   | 22.8 ms              | 1.03x faster | Significant (t=11.36)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_fft                      | 154 ms    | 153 ms               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_lu                       | 55.4 ms   | 57.0 ms              | 1.03x slower | Significant (t=-5.67)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_monte_carlo              | 32.8 ms   | 32.8 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_sor                      | 57.8 ms   | 56.9 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_sparse_mat_mult          | 2.75 ms   | 2.76 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| shortest_path                    | 316 ms    | 318 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| spectral_norm                    | 47.7 ms   | 51.6 ms              | 1.08x slower | Significant (t=-2.01)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sphinx                           | 465 ms    | 467 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_normalize             | 50.3 ms   | 50.2 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_optimize              | 24.2 ms   | 24.4 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_parse                 | 576 us    | 572 us               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_transpile             | 724 us    | 722 us               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlite_synth                     | 1.14 us   | 1.15 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| subparsers                       | 20.6 ms   | 20.7 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_expand                     | 181 ms    | 184 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_integrate                  | 8.54 ms   | 8.55 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_str                        | 103 ms    | 105 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_sum                        | 55.9 ms   | 56.0 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| telco                            | 3.39 ms   | 3.34 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| tomli_loads                      | 971 ms    | 982 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| typing_runtime_protocols         | 73.2 us   | 73.6 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpack_sequence                  | 25.2 ns   | 23.0 ns              | 1.10x faster | Significant (t=7.03)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle                         | 6.99 us   | 7.05 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle_list                    | 2.07 us   | 2.10 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle_pure_python             | 105 us    | 104 us               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_generate               | 40.5 ms   | 40.7 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_iterparse              | 49.7 ms   | 50.4 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_parse                  | 77.2 ms   | 79.1 ms              | 1.02x slower | Significant (t=-16.14) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_process                | 29.5 ms   | 29.8 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+

  • Issue: Add .take_bytes([n]) a zero-copy path from bytearray to bytes #139871

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cosmicexplorer reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@cmaloney
pythongh-139871: Update bytearray to contain PyBytesObject
daf8e02
This sets up so the bytes can be "taken" as a byes object without
requiring a copy.

I ran pyperformance (results below) and don't see any major speedups
or slowdowns with this; all seems to be in the noise of my machine.

------

pyperformance compare main.json bytearray_bytes.json -O table
main.json
=========

Performance version: 1.11.0
Report on Linux-6.17.1-arch1-1-x86_64-with-glibc2.42
Number of logical CPUs: 32
Start date: 2025-10-14 00:55:52.519236
End date: 2025-10-14 02:23:01.308400

bytearray_bytes.json
====================

Performance version: 1.11.0
Report on Linux-6.17.1-arch1-1-x86_64-with-glibc2.42
Number of logical CPUs: 32
Start date: 2025-10-13 23:22:29.928152
End date: 2025-10-14 00:49:34.467284

+----------------------------------+-----------+----------------------+--------------+------------------------+
| Benchmark                        | main.json | bytearray_bytes.json | Change       | Significance           |
+==================================+===========+======================+==============+========================+
| 2to3                             | 137 ms    | 136 ms               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_generators                 | 193 ms    | 195 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_cpu_io_mixed          | 285 ms    | 286 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_cpu_io_mixed_tg       | 289 ms    | 290 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager                 | 50.4 ms   | 51.5 ms              | 1.02x slower | Significant (t=-10.40) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_cpu_io_mixed    | 223 ms    | 225 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_cpu_io_mixed_tg | 263 ms    | 264 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_io              | 370 ms    | 372 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_io_tg           | 380 ms    | 384 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_memoization     | 125 ms    | 126 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_memoization_tg  | 161 ms    | 162 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_eager_tg              | 125 ms    | 125 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_io                    | 366 ms    | 360 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_io_tg                 | 359 ms    | 361 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_memoization           | 177 ms    | 181 ms               | 1.02x slower | Significant (t=-9.20)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_memoization_tg        | 188 ms    | 189 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_none                  | 151 ms    | 151 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| async_tree_none_tg               | 150 ms    | 151 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_tcp                      | 182 ms    | 161 ms               | 1.13x faster | Significant (t=32.85)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_tcp_ssl                  | 548 ms    | 553 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| asyncio_websockets               | 342 ms    | 339 ms               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bench_mp_pool                    | 7.12 ms   | 7.08 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bench_thread_pool                | 818 us    | 819 us               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| bpe_tokeniser                    | 2.10 sec  | 2.09 sec             | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| chaos                            | 27.9 ms   | 28.0 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| comprehensions                   | 7.45 us   | 7.24 us              | 1.03x faster | Significant (t=3.27)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| connected_components             | 308 ms    | 309 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| coroutines                       | 11.1 ms   | 11.2 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| coverage                         | 33.6 ms   | 34.1 ms              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| create_gc_cycles                 | 1.16 ms   | 1.16 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| crypto_pyaes                     | 37.1 ms   | 35.6 ms              | 1.04x faster | Significant (t=10.63)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| dask                             | 347 ms    | 351 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy                         | 118 us    | 117 us               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy_memo                    | 12.8 us   | 12.7 us              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deepcopy_reduce                  | 1.32 us   | 1.34 us              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| deltablue                        | 1.65 ms   | 1.64 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| django_template                  | 17.9 ms   | 17.8 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| docutils                         | 1.19 sec  | 1.20 sec             | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| dulwich_log                      | 19.5 ms   | 19.7 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| fannkuch                         | 184 ms    | 181 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| float                            | 37.1 ms   | 36.7 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| gc_traversal                     | 3.04 ms   | 2.84 ms              | 1.07x faster | Significant (t=19.48)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| generators                       | 15.9 ms   | 15.3 ms              | 1.04x faster | Significant (t=7.03)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| genshi_text                      | 11.3 ms   | 11.2 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| genshi_xml                       | 25.5 ms   | 25.5 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| go                               | 57.6 ms   | 56.7 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| hexiom                           | 2.92 ms   | 2.88 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| html5lib                         | 26.0 ms   | 26.5 ms              | 1.02x slower | Significant (t=-9.20)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| json_dumps                       | 4.48 ms   | 4.44 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| json_loads                       | 11.7 us   | 11.7 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| k_core                           | 1.41 sec  | 1.42 sec             | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_format                   | 3.27 us   | 3.30 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_silent                   | 45.5 ns   | 45.8 ns              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| logging_simple                   | 3.02 us   | 3.01 us              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| mako                             | 6.02 ms   | 6.03 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| many_optionals                   | 473 us    | 478 us               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| mdp                              | 587 ms    | 578 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| meteor_contest                   | 50.2 ms   | 50.5 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| nbody                            | 54.6 ms   | 52.4 ms              | 1.04x faster | Significant (t=10.72)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| nqueens                          | 41.7 ms   | 40.4 ms              | 1.03x faster | Significant (t=6.79)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pathlib                          | 9.77 ms   | 9.73 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle                           | 5.99 us   | 6.01 us              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_dict                      | 12.5 us   | 12.8 us              | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_list                      | 1.98 us   | 1.96 us              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pickle_pure_python               | 149 us    | 150 us               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pidigits                         | 111 ms    | 115 ms               | 1.03x slower | Significant (t=-18.53) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pprint_pformat                   | 737 ms    | 748 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pprint_safe_repr                 | 362 ms    | 369 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| pyflate                          | 211 ms    | 205 ms               | 1.03x faster | Significant (t=7.43)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| python_startup                   | 7.88 ms   | 7.88 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| python_startup_no_site           | 4.72 ms   | 4.76 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| raytrace                         | 130 ms    | 128 ms               | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_compile                    | 50.0 ms   | 50.2 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_dna                        | 101 ms    | 103 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_effbot                     | 1.72 ms   | 1.77 ms              | 1.03x slower | Significant (t=-26.42) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| regex_v8                         | 12.5 ms   | 12.3 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| richards                         | 20.4 ms   | 20.0 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| richards_super                   | 23.4 ms   | 22.8 ms              | 1.03x faster | Significant (t=11.36)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_fft                      | 154 ms    | 153 ms               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_lu                       | 55.4 ms   | 57.0 ms              | 1.03x slower | Significant (t=-5.67)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_monte_carlo              | 32.8 ms   | 32.8 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_sor                      | 57.8 ms   | 56.9 ms              | 1.02x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| scimark_sparse_mat_mult          | 2.75 ms   | 2.76 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| shortest_path                    | 316 ms    | 318 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| spectral_norm                    | 47.7 ms   | 51.6 ms              | 1.08x slower | Significant (t=-2.01)  |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sphinx                           | 465 ms    | 467 ms               | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_normalize             | 50.3 ms   | 50.2 ms              | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_optimize              | 24.2 ms   | 24.4 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_parse                 | 576 us    | 572 us               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlglot_v2_transpile             | 724 us    | 722 us               | 1.00x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sqlite_synth                     | 1.14 us   | 1.15 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| subparsers                       | 20.6 ms   | 20.7 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_expand                     | 181 ms    | 184 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_integrate                  | 8.54 ms   | 8.55 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_str                        | 103 ms    | 105 ms               | 1.02x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| sympy_sum                        | 55.9 ms   | 56.0 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| telco                            | 3.39 ms   | 3.34 ms              | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| tomli_loads                      | 971 ms    | 982 ms               | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| typing_runtime_protocols         | 73.2 us   | 73.6 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpack_sequence                  | 25.2 ns   | 23.0 ns              | 1.10x faster | Significant (t=7.03)   |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle                         | 6.99 us   | 7.05 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle_list                    | 2.07 us   | 2.10 us              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| unpickle_pure_python             | 105 us    | 104 us               | 1.01x faster | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_generate               | 40.5 ms   | 40.7 ms              | 1.00x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_iterparse              | 49.7 ms   | 50.4 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_parse                  | 77.2 ms   | 79.1 ms              | 1.02x slower | Significant (t=-16.14) |
+----------------------------------+-----------+----------------------+--------------+------------------------+
| xml_etree_process                | 29.5 ms   | 29.8 ms              | 1.01x slower | Not significant        |
+----------------------------------+-----------+----------------------+--------------+------------------------+
@bedevere-app bedevere-app Bot added the awaiting review label Oct 14, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Oct 14, 2025
Add .take_bytes([n]) a zero-copy path from bytearray to bytes #139871
Closed
@blurb-it
📜🤖 Added by blurb_it.
39b2d15
vstinner
vstinner reviewed Oct 14, 2025
View reviewed changes
Comment thread Include/cpython/bytearrayobject.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
Add bytearray.take_bytes
86faf1d
@cmaloney cmaloney changed the title gh-139871: Update bytearray to contain PyBytesObject gh-139871: Implement bytearray.take_bytes([n]) to efficiently extract bytes Oct 15, 2025
@cmaloney
Merge branch 'main' into bytearray_bytes
a9328f4
@cmaloney cmaloney changed the title gh-139871: Implement bytearray.take_bytes([n]) to efficiently extract bytes gh-139871: Add bytearray.take_bytes([n]) to efficiently extract bytes Oct 15, 2025
vstinner
vstinner reviewed Oct 15, 2025
View reviewed changes
Comment thread Doc/library/stdtypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/stdtypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney
cmaloney commented Oct 15, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2025-10-14-18-24-16.gh-issue-139871.SWtuUz.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney and others added 3 commits October 15, 2025 10:42
@cmaloney @vstinner
Update Objects/bytearrayobject.c
e9f5ca9
Co-authored-by: Victor Stinner <[email protected]>
@cmaloney
Review fixes
4784957
@cmaloney
Merge branch 'main' into bytearray_bytes
db19def
cmaloney
cmaloney commented Oct 15, 2025
View reviewed changes
Comment thread Lib/test/test_bytes.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney

cmaloney commented Oct 15, 2025

Copy link
Copy Markdown
Contributor Author

Threading tests found a non-threading issue that after this change ba = bytearray(b'123'); ba.clear(); ba.copy() has slightly different internals (sizeof, alloc) than before. Exploring options.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maurycy
maurycy reviewed Oct 16, 2025
View reviewed changes
Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney @maurycy
Update Objects/bytearrayobject.c
451c302
Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
maurycy
maurycy reviewed Oct 17, 2025
View reviewed changes
Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney and others added 5 commits October 17, 2025 17:17
@cmaloney
Add tests around alloc and getsizeof that show clearing isn't working…
bab7151
… which is resulting in threading failure
@cmaloney
Fix resizing to 0 length / clearing leaving one byte alloc
cb2377c
@cmaloney @maurycy
review fix: handle NULL return from from PyBytes_FromStringAndSize
20175f8
Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
@cmaloney
Add take_bytes to test_free_threading
e485595
@cmaloney
Missed line...
b5535d0
cmaloney
cmaloney commented Oct 18, 2025
View reviewed changes
Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_bytes.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney added 2 commits October 17, 2025 20:00
@cmaloney
Simplify getting out ob_bytes
7c6e8a8
@cmaloney
Include PyBytesObject in __alloc__ of bytearray.
4e27d13
cmaloney
cmaloney commented Oct 18, 2025
View reviewed changes
Comment thread Objects/bytearrayobject.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney
cmaloney commented Oct 18, 2025
View reviewed changes
Comment thread Objects/bytearrayobject.c Outdated
return PyLong_FromSsize_t(FT_ATOMIC_LOAD_SSIZE_RELAXED(self->ob_alloc));
Py_ssize_t alloc = FT_ATOMIC_LOAD_SSIZE_RELAXED(self->ob_alloc);
if (alloc > 0) {
alloc += sizeof(PyBytesObject);

@cmaloney cmaloney Oct 18, 2025

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding in the size of PyBytesObject here (and in sizeof) because ob_alloc is expected by code to be the number of bytes of space available (vs ob_size, the number of bytes in use). Felt more straightforward to me to leave ob_alloc and ob_size definitions as they were and rather add in to the size reporting here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cmaloney

cmaloney commented Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

@vstinner I think this is ready for another pass; I left github comments around some places I am unsure the CPython standard way to do as well as ones where I'm not sure what the right decision is

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

cmaloney added 3 commits November 4, 2025 11:56
@cmaloney
Fix intermittent failure on deallocation from uninitialized memory
fb84c14
@cmaloney
PEP 7
0258891
@cmaloney
Tweak comment
c470178
@cmaloney cmaloney added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 4, 2025
@bedevere-bot

bedevere-bot commented Nov 4, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @cmaloney for commit c470178 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140128%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 4, 2025
@vstinner

vstinner commented Nov 6, 2025

Copy link
Copy Markdown
Member

ARM Raspbian PR
x86 Debian Installed with X PR
x86 Debian Non-Debug with X PR

FAIL: test_fromstringandsize (test.test_capi.test_bytearray.CAPITest.test_fromstringandsize).

These 3 buildbot workers are 32-bit systems.

buildbot/AMD64 Arch Linux Asan Debug PR
buildbot/AMD64 Arch Linux Asan PR
buildbot/AMD64 Arch Linux Perf PR
buildbot/AMD64 Arch Linux TraceRefs PR
buildbot/AMD64 Arch Linux Usan Function PR
buildbot/ARM64 macOS PR
buildbot/ARM64 Raspbian PR

Unrelated test_urllib2net failure.

cmaloney reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney

cmaloney commented Nov 6, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Yea, I haven't figured out why the MemoryError isn't being raised by bytes on 32 bit systems. Can remove the test for making a bytearray sized PY_SSIZE_T_MAX - sys.getsizeof(b'') but worry I have an integer wrapping bug or similar causing it that would be better to resolve.

Investigating those 32 bit builders failures is where I noticed the warnings the other day :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
Add +1 so allocation is over max byte length
9681135
On 32 bit systems with 4GB of ram there may be PY_SSIZE_T_MAX
allocatable and the testt would pass as the allocation would succeed.

Add a + 1 so that it's over the max bytes length and an OverflowError
will be raised by bytes.
@cmaloney

cmaloney commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

!buildbot x86 Debian

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Nov 7, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @cmaloney for commit 9681135 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140128%2Fmerge

The command will test the builders whose names match following regular expression: x86 Debian

The builders matched are:

  • x86 Debian Installed with X PR
  • x86 Debian Non-Debug with X PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
Minor tweak for flow in whatsnew entry
442692a
@cmaloney

cmaloney commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

!buildbot x86 Debian|ARM Raspbian

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot

bedevere-bot commented Nov 7, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @cmaloney for commit 442692a 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140128%2Fmerge

The command will test the builders whose names match following regular expression: x86 Debian|ARM Raspbian

The builders matched are:

  • x86 Debian Installed with X PR
  • x86 Debian Non-Debug with X PR
  • ARM Raspbian Linux Asan PR
  • ARM Raspbian PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney

cmaloney commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

I think this is good to go. I have a couple follow up performance improvements (no-copy iconcat when empty and uniquely referenced bytes; minimize copying in take_bytes) but I think those are best for separate PRs.

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

vstinner
vstinner approved these changes Nov 7, 2025
View reviewed changes

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
encukou
encukou approved these changes Nov 7, 2025
View reviewed changes

@encukou encukou left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A few (hopefully final) docs nitpicks:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Doc/library/stdtypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/stdtypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Doc/library/stdtypes.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

cmaloney and others added 2 commits November 7, 2025 09:21
@cmaloney @encukou
Apply suggestions from code review
ee0d6d6
Co-authored-by: Petr Viktorin <[email protected]>
@encukou
Merge branch 'main' into bytearray_bytes
cc238c2
@encukou
encukou enabled auto-merge (squash) November 13, 2025 12:55
@encukou
encukou merged commit 732224e into python:main Nov 13, 2025
46 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Nov 13, 2025
@vstinner

vstinner commented Nov 13, 2025

Copy link
Copy Markdown
Member

Congrats @cmaloney, it's a nice enhancement! I expect follow-up PRs to use take_bytes() in the stdlib :-)

vstinner, cmaloney, and emmatyping reacted with hooray emoji vstinner, efimov-mikhail, and emmatyping reacted with rocket emoji
All reactions
  • 🎉 3 reactions
  • 🚀 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@maurycy

maurycy commented Nov 13, 2025

Copy link
Copy Markdown
Contributor

@cmaloney Congratulations!

cmaloney reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@cmaloney
cmaloney deleted the bytearray_bytes branch November 13, 2025 18:55
@cmaloney

cmaloney commented Nov 13, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing and helping with the PR! More PRs coming shortly, old bugs first :)

vstinner reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 13, 2025
@CuriousLearner
Merge branch 'main' into fix-issue21914
b9f473c
* main: (463 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 14, 2025
@CuriousLearner
Merge branch 'main' of github.com:python/cpython into fix-Issue18387
c46ecc5
* 'main' of github.com:python/cpython: (464 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
CuriousLearner added a commit to CuriousLearner/cpython that referenced this pull request Nov 14, 2025
@CuriousLearner
Merge branch 'main' of github.com:python/cpython into fix-issue24255
c240289
* 'main' of github.com:python/cpython: (464 commits)
  pythongh-140601: Add ResourceWarning to iterparse when not closed (pythonGH-140603)
  pythongh-137969: Fix double evaluation of `ForwardRef`s which rely on globals (python#140974)
  pythongh-139109: A new tracing JIT compiler frontend for CPython (pythonGH-140310)
  pythongh-141004: Document `PyErr_RangedSyntaxLocationObject` (python#141521)
  pythongh-140873: Add support of non-descriptor callables in functools.singledispatchmethod() (pythonGH-140884)
  pythongh-139653: Add PyUnstable_ThreadState_SetStackProtection() (python#139668)
  pythongh-141004: Document `PyCode_Optimize` (pythonGH-141378)
  pythongh-141004: Document C APIs for dictionary keys, values, and items (pythonGH-141009)
  pythongh-137959: Fix `TIER1_TO_TIER2` macro name in JIT InternalDocs (pythonGH-141496)
  pythongh-139871: Add `bytearray.take_bytes([n])` to efficiently extract `bytes` (pythonGH-140128)
  pythongh-140601: Refactor ElementTree.iterparse() tests (pythonGH-141499)
  pythongh-135801: Add the module parameter to compile() etc (pythonGH-139652)
  pythongh-140260: fix data race in `_struct` module initialization with subinterpreters (python#140909)
  pythongh-137109: refactor warning about threads when forking (python#141438)
  pythongh-141004: Document `PyRun_InteractiveOneObject` (pythonGH-141405)
  pythongh-124111: Fix TCL 9 thread detection (pythonGH-128103)
  pythongh-141442: Add escaping to iOS testbed arguments (python#141443)
  pythongh-140936: Fix JIT assertion crash at finalization if some generator is alive (pythonGH-140969)
  Add details about JIT build infrastructure and updating dependencies to `Tools/jit` (python#141167)
  pythongh-141412: Use reliable target URL for urllib example (pythonGH-141428)
  ...
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@cmaloney @vstinner
@maurycy @StanFromIreland
pythongh-139871: Add bytearray.take_bytes([n]) to efficiently extra…
324e322
…ct `bytes` (pythonGH-140128)

Update `bytearray` to contain a `bytes` and provide a zero-copy path to
"extract" the `bytes`. This allows making several code paths more efficient.

This does not move any codepaths to make use of this new API. The documentation
changes include common code patterns which can be made more efficient with
this API.

---

When just changing `bytearray` to contain `bytes` I ran pyperformance on a
`--with-lto --enable-optimizations --with-static-libpython` build and don't see
any major speedups or slowdowns with this; all seems to be in the noise of
my machine (Generally changes under 5% or benchmarks that don't touch
bytes/bytearray).


Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner approved these changes
@encukou encukou encukou approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
+1 more reviewer
@maurycy maurycy maurycy left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@cmaloney @vstinner @picnixz @encukou @bedevere-bot @maurycy
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.