-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
FURB109 explanation is technically incorrect #44
Comments
I created this Godbolt link in case you or anyone else wants to play with this more. Perhaps there are instances where the bytecode would differ, but from the few examples I tried the bytecode was the same. I think propping up this check as a "performance" boost is misleading, and should be changed. Perhaps making this a "consistency" check would be more beneficial. If that is the case, users should be able to specify whether they would prefer |
And yes, sets/frozensets are potentially faster if you have many elements, but in my opinion they look "gross", and I seldom see any codebases using sets literals for |
I didn't know you could use godbolt on Python. I'm not sure why they look gross, containership is a natural question for a set or a dict, while it's "hacked on" to a list / tuple as a convenience - it's just a looping check. I was strongly in favor of Agree on consistency (and I'm not against the check - though picking one over the other is stylistic rather than performance). |
I think gross is too strong of a word. Perhaps my dislike comes from the fact that |
I found this discussion fascinating and learned something from it. In fairness to So when running against code still supporting <=3.7, the tool is technically still correct. 😉 |
This:
Is wrong. Besides the fact tuples are not usually more performant than lists, the expression in question actually produces the same byte code:
In general, lists tend to be homogenous variable length "lists" and tuples heterogeneous data.
This actually is potentially faster and is logically the correct thing:
However, it's not equivalent - the items need to be hashable, and the comparison is not quite the same. Sets are also much slower to construct, but as long as they are inline they are directly loaded in byte code. This could be much faster to check, but that depends on the size, and inline is not likely to be that large.
The text was updated successfully, but these errors were encountered: