Skip to content

Conversation

@erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Apr 2, 2024

@erlend-aasland
Copy link
Contributor Author

cc. faster-cpython/ideas#671

@erlend-aasland erlend-aasland changed the title Draft: adapt str.{start,end}swith to Argument Clinic gh-117431: Adapt str.{start,end}swith to use the METH_FASTCALL calling convention Apr 2, 2024
@erlend-aasland erlend-aasland marked this pull request as ready for review April 2, 2024 15:37
@erlend-aasland
Copy link
Contributor Author

# main
$ ./python.exe -m timeit -s "s = 'abcdef'" "s.startswith('abc')"
5000000 loops, best of 5: 89.1 nsec per loop

# this PR
$ ./python.exe -m timeit -s "s = 'abcdef'" "s.startswith('abc')"
10000000 loops, best of 5: 26.4 nsec per loop

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Apr 2, 2024

We'll also want to convert str.find and friend and finally get rid of the parsing helper in strlib. However, that is best left to a follow-up PR (#117468). I prefer small and incremental changes.

@erlend-aasland
Copy link
Contributor Author

Thanks for the review, @JelleZijlstra and @eendebakpt. I'll hold off merging for a day or two.

@erlend-aasland
Copy link
Contributor Author

erlend-aasland commented Apr 3, 2024

Well, with two core devs approving, I'll go ahead and merge. Thanks for the reviews.

@erlend-aasland erlend-aasland merged commit 444156e into python:main Apr 3, 2024
@erlend-aasland erlend-aasland deleted the perf/starwith branch April 3, 2024 07:11
@vstinner
Copy link
Member

vstinner commented Apr 4, 2024

Nice optimization!

diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…inic (python#117466)

This change gives a significant speedup, as the METH_FASTCALL calling
convention is now used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants