8000 Improve performance of startswith, endswith, count, *find, and *index methods for str, bytes and bytearray · Issue #117431 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Improve performance of startswith, endswith, count, *find, and *index methods for str, bytes and bytearray #117431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
eendebakpt opened this issue Apr 1, 2024 · 3 comments
Labels
3.13 bugs and security fixes performance Performance or resource usage type-feature A feature request or enhancement

Comments

@eendebakpt
Copy link
Contributor
eendebakpt commented Apr 1, 2024

Feature or enhancement

Proposal:

We can improve performance of str.startswith and other methods for the single-argument case by creating a fast path in the single argument parsing.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

faster-cpython/ideas#671

Linked PRs

@eendebakpt

This comment was marked as off-topic.

erlend-aasland added a commit that referenced this issue Apr 3, 2024
…117466)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used.
@erlend-aasland erlend-aasland changed the title Improve performance of startswith and endswith methods for str and bytes Improve performance of startswith, endswith, count, *find, and *index methods for str, bytes and bytearray Apr 3, 2024
@erlend-aasland
Copy link
Contributor

Conversion of bytes/bytearray find() and friends1 is not straight-forward: the first argument can be either a buffer or an index in the range [0,255]. The code is shared between bytes and bytearray2. My first thought would be to create a custom Argument Clinic converter3, but we'd want that also to be shared between bytes and bytearray.

Footnotes

  1. rfind, index, rindex, count

  2. Objects/bytes_methods.c

  3. a combination of one Argument Clinic Python input block and one C function

erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Apr 3, 2024
The first parameter is named 'suffix', not 'prefix'.

Regression introduced by commit 444156e
erlend-aasland added a commit that referenced this issue Apr 3, 2024
The first parameter is named 'suffix', not 'prefix'.

Regression introduced by commit 444156e
erlend-aasland added a commit that referenced this issue Apr 3, 2024
… Argument Clinic (#117495)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used.
erlend-aasland added a commit that referenced this issue Apr 3, 2024
This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following methods are adapted:

- str.count
- str.find
- str.index
- str.rfind
- str.rindex
@hugovk
Copy link
Member
hugovk commented Apr 3, 2024

Nice work so far! Would be good to put these in What's New, perhaps under https://docs.python.org/3.13/whatsnew/3.13.html#optimizations.

Can be done later, when closing the issue.

erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue Apr 6, 2024
erlend-aasland added a commit that referenced this issue Apr 12, 2024
…Clinic (#117502)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following bytes and bytearray methods are adapted:

- count()
- find()
- index()
- rfind()
- rindex()

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…inic (python#117466)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
The first parameter is named 'suffix', not 'prefix'.

Regression introduced by commit 444156e
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…h() to Argument Clinic (python#117495)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used.
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…n#117468)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following methods are adapted:

- str.count
- str.find
- str.index
- str.rfind
- str.rindex
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…ument Clinic (python#117502)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used. The following bytes and bytearray methods are adapted:

- count()
- find()
- index()
- rfind()
- rindex()

Co-authored-by: Inada Naoki <songofacandy@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes performance Performance or resource usage type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants
0