Modern Optimization (was: Beazley's Problem)

Liste des GroupesRevenir à cl python 
Sujet : Modern Optimization (was: Beazley's Problem)
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 26. Sep 2024, 14:51:13
Autres entêtes
Organisation : Stefan Ram
Message-ID : <optimizations-20240926134921@ram.dialup.fu-berlin.de>
References : 1 2 3 4 5 6
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.



Date Sujet#  Auteur
21 Sep 24 * Beazley's Problem14Stefan Ram
21 Sep 24 `* Re: Beazley's Problem13Paul Rubin
21 Sep 24  `* Re: Beazley's Problem12Stefan Ram
21 Sep 24   `* Re: Beazley's Problem11Paul Rubin
23 Sep 24    `* Re: Beazley's Problem10Annada Behera
23 Sep 24     +* Re: Beazley's Problem8Stefan Ram
24 Sep 24     i+- Re: Beazley's Problem (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
24 Sep 24     i+* Re: Beazley's Problem4Paul Rubin
24 Sep 24     ii+- Re: Beazley's Problem1Annada Behera
10 Nov22:48     ii`* Re: Beazley's Problem2david k. combs
10 Nov23:55     ii `- Re: Beazley's Problem1Paul Rubin
26 Sep 24     i`* Modern Optimization (was: Beazley's Problem)2Stefan Ram
26 Sep 24     i `- Re: Modern Optimization1Stefan Ram
6 Oct 24     `- Re: Beazley's Problem1Antoon Pardon

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal