#14297: Accessing settings.FOO in hot spots cause performance problems -----------------------------------+---------------------------------------- Reporter: akaariai | Owner: akaariai Status: new | Milestone: Component: Core framework | Version: SVN Keywords: settings, performance | Stage: Unreviewed Has_patch: 1 | -----------------------------------+---------------------------------------- Trying to access settings.FOO (no matter if it exists or not) will cause performance problems if used in hot spots of code. The reason is that settings is actually LazyObject, and each access goes through __getattr__. The problem is well illustrated in ticket #14290, where performance is increased considerably if a setting is cached in a global attribute.
I am trying to fix this by refactoring LazySettings in the following way: Make the new LazySettings be a regular Python object, but with a special __getattr__ method: When first accessed, it will set up the settings in the objects own __dict__. After this, each access to settings.FOO, where FOO exists, will not use __getattr__. When trying to access settings.BAR, where BAR does not exist, the access will still need to go through __getattr__. This should not be a performance problem, though. The performance increase on my laptop (using the test from #14290, with USE_L10N = False) is from 1.1 to 0.8 seconds, or 0.3 seconds. This is the cost of accessing settings.USE_L10N 60000 times and settings.USE_I18N 10000 times, plus fifteen other accesses. (The test is the http://localhost:8000/test/10000?timing one). Attached patch passes all tests (I know how to run). -- Ticket URL: <http://code.djangoproject.com/ticket/14297> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.