Re:Python’s Weak Performance Matters
by PyComfy on Thursday February 08, 2018 @01:54PM
(#16334542)
ah sorry. i did
which gave
[ Parent
| on HN ]
Re:Python’s Weak Performance Matters
by tom_mellior on Thursday February 08, 2018 @04:17PM
(#16335674)
Ah, OK. Yes, those LOAD_NAMEs are slower than LOAD_FAST. If you put the code into a function, you get this:
>>> def f(foo, b):
... a = foo.bar(b)
...
>>> dis.dis(f)
2 0 LOAD_FAST 0 (foo)
3 LOAD_ATTR 0 (bar)
6 LOAD_FAST 1 (b)
9 CALL_FUNCTION 1 (1 positional, 0 keyword pair)
12 STORE_FAST 2 (a)
15 LOAD_CONST 0 (None)
18 RETURN_VALUE
LOAD_FAST is the normal case for locals inside a function. Not sure off the top of my head where LOAD_NAME would be generated in normal usage (i.e. where you don't evaluate code from a string).Edit: Also, I'm talking about Python 3. Maybe you aren't.