Opened 7 years ago

Closed 7 years ago

#27625 closed Cleanup/optimization (fixed)

Make Settings avoid repeat getattr calls

Reported by: Adam Johnson Owned by: Adam Johnson
Component: Core (Other) Version: 1.10
Severity: Normal Keywords:
Cc: me@…, carl@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Carl Meyer's talk at DUTH on Instagram he noted a small 'hack' that add been added to their codebase to speed up all their requests: caching the first result of settings accesses in the outer LazySettings object's __dict__ with a post-setup hook like:

for key in dir(settings):
    settings.__dict__[key] = getattr(settings, key)

LazySettings itself could do this caching in its own __dict__ to give great speed to all! It can also be done in a way that is tested to interact better with other parts of Django, such as override_settings.

Change History (2)

comment:1 by Tim Graham, 7 years ago

Has patch: set
Triage Stage: UnreviewedReady for checkin

comment:2 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In c1b221a9:

Fixed #27625 -- Made LazySettings cache attributes in dict.

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