Glyph Lefkowitz <glyph@twistedmatrix.com> writes: > Method calls appear are a full 20% slower (simple benchmark included) than > function calls, and Python function calls are already pretty slow. By my > understanding, one of the reasons for the difference is that if you have a > method call like this: > > a = A() > a.b() > > what's really happening is something along the lines of: > > temp = new.instancemethod(getattr(a.__class__, "b"), a, A) > temp() > free(temp) > > This causes an unnecessary memory allocation: since the instancemethod object > is immediately being created, then called, then garbage collected. Looking at > the output of dis.dis, I can see there are also 3 bytecodes being evaluated > rather than 1. Can this allocation be avoided? Ahh, by the 'atomic' implementation of the single CALL_ATTR opcode, using a static allocated instancemethod instead of a new one? Is this what you have in mind? Thomas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4