[Python-Dev] genexps slow? (original) (raw)
Tim Peters tim.one at comcast.net
Sun Apr 4 20:50:05 EDT 2004
- Previous message: [Python-Dev] Re: Python-Dev Digest, Vol 9, Issue 16
- Next message: [Python-Dev] genexps slow?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Tim Peters]
Resuming a generator function is a lot cheaper than calling a function, but there's still a non-trivial amount of code to get in and out of evalframe() each time, which the listcomp version gets to skip.
[Michael Hudson.
This is something that occurred to me a while ago: how many opcodes does a typical invocation of evalframe actually execute? A little script told me that the median length of functions in Lib/*.py was 38 instructions (or 52 bytes) IIRC, but obviously a dynamic count is far more interesting. If the number is fairly small (and honestly, I have no idea), the set up and tear down code becomes much more significant than one might think.
And whatever it is, I expect it will be significantly smaller for functions synthesized to implement generator expressions.
I didn't think much about the code to get out of evalframe.
There's a twist there: the functions synthesized for generator expressions get to take the quicker-than-general "fast_yield" exit path. Hmm! It looks like tests against WHY_YIELD before the fast_yield label can no longer succeed, but are still there to slow down non-generator cases.
- Previous message: [Python-Dev] Re: Python-Dev Digest, Vol 9, Issue 16
- Next message: [Python-Dev] genexps slow?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]