Opened 3 hours ago

Last modified 2 hours ago

#35893 assigned Cleanup/optimization

Using list comprehension (instead of a generator) to any/all where the items are side-effect free is a performance error

Reported by: john-parton Owned by: john-parton
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When passing a generator to any() or all(), Python can perform short-circuit evaluation to avoid needless computation.

Directly passing a list using list-comprehension is generally not recommended, unless the list-comprehension has a side-effect (for example calling a method that sets attributes on an object)

There's at least one place in the code-base where it's safe to replace list comprehension with a generator and get the short-circuit optimization for "free."

Change History (1)

comment:1 by john-parton, 2 hours ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top