Skip to content

[mypyc] Add faster primitive for string equality - #19402

Merged
JukkaL merged 2 commits into
masterfrom
mypyc-str-equal
Jul 9, 2025
Merged

JukkaL merged 2 commits into
masterfrom
mypyc-str-equal

Conversation

@JukkaL

@JukkaL JukkaL commented Jul 8, 2025 •

Copy link
Copy Markdown
Collaborator

This speeds up self check by ~1.4%. String equality is one of the top
five most common primitive function calls in self check.

We previously used a string comparison primitive that calculated the
relative order of two strings. Usually we only care about equality,
which we can do quicker since we can fast path using a length check,
for example.

I checked the CPython implementation of string equality in 3.9 (lowest
supported Python version) and 3.13, and both of them had a fast path
based on string object kind, and equality checks overall had the same
semantics.

Current CPython implementation:
https://github.com/python/cpython/blob/main/Objects/stringlib/eq.h

Tests for this were added in #19401.

JukkaL added 2 commits July 8, 2025 14:28
This speeds up self check by ~1.4%.  String equality is one of the top
five most common primitive function calls in self check.

We previously used a string comparison primitive that calculated the
relative order of two strings. Usually we only care about equality,
which we can do quicker since we can fast path using a length check,
for example.

I checked the CPython implementation of string equality in 3.9 (lowest
supported Python version) and 3.13, and both of them had a fast path
based on string object kind, and equality checks overall have the same
semantics.
@JukkaL
JukkaL requested a review from ilevkivskyi July 8, 2025 17:23

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

@JukkaL
JukkaL merged commit 10f95e6 into master Jul 9, 2025
@JukkaL
JukkaL deleted the mypyc-str-equal branch July 9, 2025 09:25
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.

2 participants