r/Python • Freelancer. AnyFactor.xyz • Sep 16 '20

News An update on Python 4

Post image
3.3k Upvotes

389 comments sorted by

View all comments

Show parent comments

-1

u/[deleted] Sep 16 '20

How do they perform faster? Surely it's the same method?

8

u/SaltyHashes Sep 16 '20

IIRC it's faster because it doesn't even have to call a method.

1

u/[deleted] Sep 17 '20

Yeah I see now, I'm surprised the JIT compiler can't make the same optimisation for the empty dict() case or with just literals inside.

1

u/[deleted] Sep 17 '20

Unless I'm remembering wrong, CPython doesn't use a JIT compiler, only PyPy does?

4

u/Emile_L Sep 17 '20

When you call dict() or any builtin the interpreter needs to first look up in locals and globals for the symbol which adds a bit of overhead.

Not sure if that's the only reason though.

0

u/hillgod Sep 16 '20

I don't know how, though I'd guess something with handling *args and **kwargs.

Here's an analysis from Stack overflow: https://stackoverflow.com/questions/5790860/and-vs-list-and-dict-which-is-better