Alex Gaynor: Fast Python, Slow Python - PyCon 2014

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 42

  • @JimmyGunawanX
    @JimmyGunawanX 7 ปีที่แล้ว +50

    Skip to 1:34 to really start.

    • @abyssalplanes
      @abyssalplanes 2 ปีที่แล้ว

      and skip that sick beat? no way!

  • @mtaur4113
    @mtaur4113 4 ปีที่แล้ว +19

    I feel like this was a lot of high-level choir preaching and sermonizing and not a whole lot of practical instruction on how to program better.

  • @tizbr
    @tizbr 9 ปีที่แล้ว +5

    he is really excellent at handling questions

  • @spoolboyy
    @spoolboyy 8 ปีที่แล้ว +6

    This was a very interesting talk. And although I enjoyed the song, I could have done without the 90 seconds of music at the beginning though. Anybody else wondering if the video editor is the lead guitarist of Gramatik?

  • @grawss
    @grawss ปีที่แล้ว

    Has this changed since this talk? Dicts now use hashmaps, so a dict with a few million entries is no different from a dict with a couple. With slots it might be faster because it avoids the dict within the class (pretty sure? I'm still a rookie), but what's the difference really? Either way we're still looking into globals, then the class key/dict key, then the value. Unless I'm missing something.
    TBH I just don't want a ton of extra code and classes and scopes when a dict is just like.. whatever you want. Plus I do a lot of text parsing, and respond a lot to text-input, so a dict lookup is way faster in this case. {'key': var} is a hashed lookup with no other conversion, whereas classes would require attribute lookups.

  • @paroxyzm21
    @paroxyzm21 10 ปีที่แล้ว +9

    Great talk!
    Can somebody point me to the place where I can learn more about Dicts vc Objects memory performance?
    It realy surprised me to hear thar dicts can use more memory than objects...
    just like the man who asked a question around 33:40

  • @younglife88
    @younglife88 7 ปีที่แล้ว +2

    Liked the talk, Speaker answers questions like if he was reading the answers haha

  • @typedeaf
    @typedeaf 9 ปีที่แล้ว +4

    I am entirely new to Python, but from what I understand, classes are implemented using a dict. For instance .__dict__ will show all of the objects attributes in their internal dictionary form. So, all classes are constructed with dicts, how could a class be faster than a dict? Are you sure this entire presentation isn't just conjecture?

    • @rvm521443
      @rvm521443 9 ปีที่แล้ว +13

      He's a core Python / PyPy developer, so it's certainly not just conjecture. If something exposes a dict-like interface it doesn't mean that it's implemented as one and has the same performance characteristics.

    • @NotoriousPyro
      @NotoriousPyro 2 ปีที่แล้ว

      Everything in Python is an object. Dicts are objects, functions are objects.

  • @thomasgandalf4111
    @thomasgandalf4111 9 ปีที่แล้ว +9

    some of these examples are definetly not pythonic (e.f. adding booleans to count 4 arguments -- don't do that

    • @Xavier-es4gi
      @Xavier-es4gi 4 ปีที่แล้ว +1

      I'm a bit late but can you explain why and what alternative would be good

  • @eqapo
    @eqapo 8 ปีที่แล้ว +1

    it would have been better to make the connection between pythonic/idiomatic code and specialized code. Either that they are the same, or that specialized code is a subset of pythonic code

  • @AJBonkoski
    @AJBonkoski 10 ปีที่แล้ว +7

    This is ridiculous and spreading mis-information: There is absolutely no good reason why the dict example cannot achieve the same performance as a C struct when used like an object. In python, a Dict is actually semantically simpler than a generic object. CPython and PyPy may not optimize it, but its 100% doable. You need only to look at the engineering behind LuaJit to see an example. This "flaw" is just a PyPy implementation detail. In X months/years from now there will likely be a better implementation that no longer has these restrictions. As always, profile the code: don't memorize this talk as fact. These conclusions are extremely likely to change.

    • @0LoneTech
      @0LoneTech 8 ปีที่แล้ว

      AJBonkoski That's not a PyPy limited implementation detail; the main difference stems from the attribute names being symbols. That implies they get interned, such that they are the same object even if created from different places (for instance, parsing some json). Classes may have further steps, like __slots__, to optimize further. Still, just interning your keys will make a huge difference when you use many similar dicts.

    • @AlexanderSchepanovski
      @AlexanderSchepanovski 6 ปีที่แล้ว

      In JavaScript dicts are the same as objects and V8 happily optimizes them, so dicts example is definitely a PyPy implementation detail.

  • @AlexanderLavin
    @AlexanderLavin 9 ปีที่แล้ว +3

    NameError in your code at 11:25...

  • @salkdjfasldkfjsdlk
    @salkdjfasldkfjsdlk 9 ปีที่แล้ว +1

    Great talk! Can you please re-record all the tech videos where people um and uh ever 5 seconds? Or at least train them to slow down and just say what they're thinking. Cheers

  • @buybuydandavis
    @buybuydandavis 3 ปีที่แล้ว

    p60 vid for a tec talk?

  • @AnkushJindaljindalankush95
    @AnkushJindaljindalankush95 9 ปีที่แล้ว +1

    Can someone point to the link of wiki page mentioned by Alex at 32:45 ?

    • @tizbr
      @tizbr 9 ปีที่แล้ว +2

      +Ankush Jindal wiki.python.org/moin/TimeComplexity

  • @teodordima3639
    @teodordima3639 10 ปีที่แล้ว

    Is the third asker Steve Yegge? Seems like his voice.

  • @esphilee
    @esphilee 4 ปีที่แล้ว +4

    Want speed, use C. Want simple, use python.
    Want speed wear running shoe, want simple wear slipper.
    You can make slipper fast, but it wouldn’t worth the effort, just get the running shoe.
    Python written in easily understand way, is python suppose to be used.

  • @futurepython6774
    @futurepython6774 2 ปีที่แล้ว

    python/django/mysql新教程:
    python基础:th-cam.com/video/g6RnSRDjd5M/w-d-xo.html

  • @MarkJay
    @MarkJay 7 ปีที่แล้ว +1

    interesting talk! need to pypy

  • @Eghizio
    @Eghizio 4 ปีที่แล้ว

    29:30 is that Aja Hammerly ? Sounds like her :D

  • @the_worst_coconut
    @the_worst_coconut 10 ปีที่แล้ว

    anyone know what the intro music was?

    • @spoolboyy
      @spoolboyy 8 ปีที่แล้ว +2

      +captain coconut
      Music "Just Jammin'" by Gramatik

  • @AndiRadyKurniawan
    @AndiRadyKurniawan 10 ปีที่แล้ว +2

    I believe in python3.4, dict is faster than classes.

    • @0LoneTech
      @0LoneTech 6 ปีที่แล้ว +2

      You're talking of CPython and overgeneralising. Dict is faster than before, but the classes that use it to implement dynamic attributes will be too, and classes with slots can be faster still. In particular, the main culprit of slowness tends to be not fitting in cache, and having an extra dictionary for every object will cost in both indirection and space. And that's before taking into account that class attribute names tend to be interned but dictionary keys don't.

  • @Xclann
    @Xclann 7 ปีที่แล้ว +1

    Talk starts at 1:53.

  • @movax20h
    @movax20h 5 ปีที่แล้ว

    Use namedtuples if possible instead.

  • @kylewood303
    @kylewood303 7 ปีที่แล้ว

    Sounds like he's talking with full of saliva in his mouth

  • @onlybrad8434
    @onlybrad8434 7 ปีที่แล้ว +1

    infinite loop ? 18:40

    • @aragonnetje
      @aragonnetje 4 ปีที่แล้ว

      yeah, but not too important to the example

  • @shipeng3923
    @shipeng3923 10 ปีที่แล้ว

    Up

  • @this-is-bioman
    @this-is-bioman 2 ปีที่แล้ว

    Dynamic typing sucks and everyone knows that! So I don't get why don't just drop this stupid idea and make them strongly typed?
    Like for example TypeScript > JavaScript so why don't you just make JS strongly typed?
    Or types hints in python!!! You make python dynamically typed, BUT then introduce type hints. It can't be more stupid than that.

  • @frepkin
    @frepkin 9 ปีที่แล้ว +1

    Python is a tool for scientists to help them write articles.

    • @tissuepaper9962
      @tissuepaper9962 3 ปีที่แล้ว +1

      And that's why trillion-dollar companies are using it on a daily basis... Go be stupid somewhere else.