Dive into CPython Bytecode

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Dive into CPython Bytecode - Presentation Transcript

    1. Dive into CPython Bytecode Alex Gaynor
    2. I don't need to know that stuff
    3. You don't. But it's totally helpful.
    4. How does CPython Make Bytecode?
    5. Tokenize the source
    6. Parse the tokens into an AST
    7. Build a symbol table to figure out what's a global
    8. Compile to bytecode
    9. Now I can haz bytecode
    10. Now that I has a bytecode how does I see it?
    11. >>> def f(o): ... return o >>> import dis >>> dis.dis(f) 2 0 LOAD_FAST 0 (o) 3 RETURN_VALUE
    12. So use the dis module
    13. So now that we have bytecode, what do we do with it?
    14. Well, what are those bytecodes?
    15. A few examples
        • UNARY_NEGATIVE: -TOS
        • BINARY_ADD: TOS1 + TOS
        • SLICE+3: TOS2[TOS1:TOS]
        • UNPACK_SEQUENCE
        • LOAD_CONST
        • CALL_FUNCTION_VAR_KW
    16. Python VM is stack based
    17. So now we know some bytecodes, what can we do with this knowledge
    18. A tale of 2 functions
      • >>> def f():
      • ... return [x for x in xrange(10)]
      • >>> def g():
      • ... o = []
      • ... for x in xrange(10):
      • ... o.append(x)
      • ... return o
    19.  
    20.  
    21. Less Bytecode == faster!
    22. More specialized bytecodes == faster
    23. @alex_gaynor Thanks
    SlideShare Zeitgeist 2009

    + Alex GaynorAlex Gaynor Nominate

    custom

    694 views, 1 favs, 0 embeds more stats

    My slides from my 2009 DjangoCon lightning talk on more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 694
      • 694 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 44
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories