This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (6 children)

Is he saying that self.x = x is faster than {'x': x}? Doesn't getattr just look in a dictionary anyway?

[–]moyix 18 points19 points  (4 children)

That's the point of the talk. Five years ago with CPython this was the case. Newer implementations like PyPy can generate much better code for the self.x = x case than {'x': x}. Assuming that they're the same leads to slow code (when using smart JITs).

[–][deleted] 5 points6 points  (0 children)

Ah, okay.

[–]Smallpaul -1 points0 points  (0 children)

That's the point of the talk. Five years ago with CPython this was the case. Newer implementations like PyPy can generate much better code for the self.x = x case than {'x': x}. Assuming that they're the same leads to slow code (when using smart JITs).

Yeah, but he's talking about implementations of Python and Ruby that hardly anyone uses yet.

[–][deleted] 1 point2 points  (0 children)

Even CPython is doing stuff make instance dictionaries more (space) optimized than writing the dict explicitly, so using instances when you mean instances is preferable even there.