Skip to content

gh-117431: Adapt str.{start,end}swith to use the METH_FASTCALL calling convention - #117466

Merged
erlend-aasland merged 6 commits into
python:mainfrom
erlend-aasland:perf/starwith
Apr 3, 2024
Merged

gh-117431: Adapt str.{start,end}swith to use the METH_FASTCALL calling convention#117466
erlend-aasland merged 6 commits into
python:mainfrom
erlend-aasland:perf/starwith

Conversation

@erlend-aasland

@erlend-aaslanderlend-aasland commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

cc. faster-cpython/ideas#671

@erlend-aaslanderlend-aasland changed the title Draft: adapt str.{start,end}swith to Argument Clinicgh-117431: Adapt str.{start,end}swith to use the METH_FASTCALL calling conventionApr 2, 2024
@erlend-aasland
erlend-aasland marked this pull request as ready for review April 2, 2024 15:37
@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor
# 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

Comment threadObjects/clinic/unicodeobject.c.h
@erlend-aasland

erlend-aasland commented Apr 2, 2024

Copy link
Copy Markdown
ContributorAuthor

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.

Comment threadObjects/unicodeobject.c Outdated
@erlend-aasland

Copy link
Copy Markdown
ContributorAuthor

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

@erlend-aasland

erlend-aasland commented Apr 3, 2024

Copy link
Copy Markdown
ContributorAuthor

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:mainApr 3, 2024
@erlend-aasland
erlend-aasland deleted the perf/starwith branch April 3, 2024 07:11
Comment threadObjects/unicodeobject.c
@vstinner

Copy link
Copy Markdown
Member

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 freeto 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

@erlend-aasland@vstinner@methane@eendebakpt@JelleZijlstra