• Modern Optimization (was: Beazley's Problem)

    From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.python on Thu Sep 26 12:51:13 2024
    From Newsgroup: comp.lang.python

    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    totally implement anything in an imperative or functional style.

    In functional programming, you don't redefine names. So,

    |let i := 7

    is still kosher with functional programming, while

    |let i := 7
    |let i := 8

    is a no-go. Why am I bringing this up?

    If you redefine a name in a Python module (since around 2022), like,

    |i = 7
    . . .
    |i = 8

    , you're putting the kibosh on a certain optimization for name lookup
    and your program's going to drag. This means that sprinkling in a little
    functional programming mojo can make your Python programs zip along!

    This was laid out by Kevin Modzelewski in a talk back in 2022.

    He dropped these nuggets for Python programs (for CPython, I take it)
    that don't cramp modern optimizations:

    - Don't reassign global variables.

    - All objects of a class should have the same attributes
    (names, not values; i.e., "obj.dict.keys()" shouldn't
    be different between objects of the same class).

    - Set the same attributes in the same order for all objects
    of a class.

    - Use slots.

    - Don't change attributes of classes of objects.

    - Don't bother trying to optimize attribute lookup for
    method calls outside of loops anymore.
    (Don't try to "cache" methods in variables.)
    The optimizer will take care of this today better
    than you could ever do.

    What else puts the brakes on a program is using module "getattr"
    methods and tracing or profiling.


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From ram@ram@zedat.fu-berlin.de (Stefan Ram) to comp.lang.python on Thu Sep 26 12:54:34 2024
    From Newsgroup: comp.lang.python

    ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
    (names, not values; i.e., "obj.dict.keys()" shouldn't

    obj.__dict__.keys()


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Gilmeh Serda@gilmeh.serda@nothing.here.invalid to comp.lang.python on Thu Sep 26 16:13:55 2024
    From Newsgroup: comp.lang.python

    On 26 Sep 2024 12:51:13 GMT, Stefan Ram wrote:

    - Use slots.

    ...or you end up with sloths? ;)
    --
    Gilmeh

    Why, every one as they like; as the good woman said when she kissed her
    cow. -- Rabelais
    --- Synchronet 3.20a-Linux NewsLink 1.114