Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[mypyc] Fast tuple equality checks - #9343

Merged
JukkaL merged 12 commits into
python:masterfrom
TH3CHARLie:tuple-equality
Aug 27, 2020
Merged

[mypyc] Fast tuple equality checks#9343
JukkaL merged 12 commits into
python:masterfrom
TH3CHARLie:tuple-equality

Conversation

@TH3CHARLie

Copy link
Copy Markdown
Collaborator

@TH3CHARLie
TH3CHARLie requested a review from JukkaL August 23, 2020 16:59
@TH3CHARLie
TH3CHARLie marked this pull request as draft August 23, 2020 16:59
@TH3CHARLie

Copy link
Copy Markdown
Collaborator Author

The tests failures are due to the runtime error described in the issue.

@TH3CHARLie

Copy link
Copy Markdown
Collaborator Author

some performance numbers(running on my mac locally, very imprecise)

On master

interpreted: 0.180333s (avg of 5 iterations; stdev 0.61%)
compiled:    0.210294s (avg of 5 iterations; stdev 0.9%)

compiled is 0.858x faster

with this PR:

interpreted: 0.182221s (avg of 6 iterations; stdev 0.51%)
compiled:    0.055916s (avg of 6 iterations; stdev 0.35%)

compiled is 3.259x faster

@TH3CHARLie
TH3CHARLie marked this pull request as ready for review August 24, 2020 12:52
@TH3CHARLie
TH3CHARLie marked this pull request as draft August 24, 2020 13:30
Comment thread mypyc/irbuild/ll_builder.py Outdated
# Cast to bool if necessary since most types uses comparison returning a object type
# See generic_ops.py for more information
if not is_bool_rprimitive(compare.type):
comapre = self.coerce(compare, bool_rprimitive, line)

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.

typo ("comapre")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! But I've already addressed that in e34c025. The problem now is the Tuple[T, ...] nested within a regular Tuple

@TH3CHARLie
TH3CHARLie marked this pull request as ready for review August 25, 2020 12:38
@TH3CHARLie

Copy link
Copy Markdown
Collaborator Author

@JukkaL I think it's ready for review now.

@msullivan msullivan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, but I have on question

Comment thread mypyc/irbuild/ll_builder.py Outdated
equal = True if op == '==' else False
result = self.alloc_temp(bool_rprimitive)
# empty tuples
if (equal and len(lhs.type.types) == 0 and len(rhs.type.types) == 0):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why a special case for just equality?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch!

@msullivan

Copy link
Copy Markdown
Collaborator

No need for this to be in this PR, but it would be pretty straightforward to do < and friends too, right?

@TH3CHARLie

TH3CHARLie commented Aug 25, 2020

Copy link
Copy Markdown
Collaborator Author

No need for this to be in this PR, but it would be pretty straightforward to do < and friends too, right?

Sure, only need to do some minor modifications. But they appear much less frequently than these two ops, so probably it's OK to lower their priority IMO.

Comment thread mypyc/irbuild/ll_builder.py Outdated
# Cast to bool if necessary since most types uses comparison returning a object type
# See generic_ops.py for more information
if not is_bool_rprimitive(compare.type):
compare = self.coerce(compare, bool_rprimitive, line)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Coerce only does a type check. I think that the normal CPython semantics would be to allow arbitrary objects that have a truth value, i.e. it may be better to use bool_op instead. Consider what happens if a user-defined class defines __eq__ that returns a non-bool value such as 1 or 'x'.

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good!

@JukkaL
JukkaL merged commit a05f19e into python:master Aug 27, 2020
@TH3CHARLie
TH3CHARLie deleted the tuple-equality branch August 27, 2020 10:45
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.

Make tuple equality faster

4 participants