Kaydet (Commit) dc8f95b6 authored tarafından evildmp's avatar evildmp

Fixed #20877 -- added a performance optimization guide

üst 4db2752e
...@@ -233,6 +233,14 @@ regions: ...@@ -233,6 +233,14 @@ regions:
* :doc:`"Local flavor" <topics/localflavor>` * :doc:`"Local flavor" <topics/localflavor>`
* :doc:`Time zones </topics/i18n/timezones>` * :doc:`Time zones </topics/i18n/timezones>`
Performance and optimization
============================
There are a variety of techniques and tools that can help get your code running
more efficiently - faster, and using fewer system resources.
* :doc:`Performance and optimization overview <topics/performance>`
Python compatibility Python compatibility
==================== ====================
......
...@@ -495,8 +495,8 @@ Atom1Feed ...@@ -495,8 +495,8 @@ Atom1Feed
For cases like this, use the ``django.utils.functional.allow_lazy()`` For cases like this, use the ``django.utils.functional.allow_lazy()``
decorator. It modifies the function so that *if* it's called with a lazy decorator. It modifies the function so that *if* it's called with a lazy
translation as the first argument, the function evaluation is delayed until it translation as one of its arguments, the function evaluation is delayed
needs to be converted to a string. until it needs to be converted to a string.
For example:: For example::
......
...@@ -1162,22 +1162,6 @@ Example:: ...@@ -1162,22 +1162,6 @@ Example::
.. _`Cache-Control spec`: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 .. _`Cache-Control spec`: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
Other optimizations
===================
Django comes with a few other pieces of middleware that can help optimize your
site's performance:
* ``django.middleware.http.ConditionalGetMiddleware`` adds support for
modern browsers to conditionally GET responses based on the ``ETag``
and ``Last-Modified`` headers.
* :class:`django.middleware.gzip.GZipMiddleware` compresses responses for all
modern browsers, saving bandwidth and transfer time. Be warned, however,
that compression techniques like ``GZipMiddleware`` are subject to attacks.
See the warning in :class:`~django.middleware.gzip.GZipMiddleware` for
details.
Order of MIDDLEWARE_CLASSES Order of MIDDLEWARE_CLASSES
=========================== ===========================
......
...@@ -88,7 +88,8 @@ of parentheses, but will call callables automatically, hiding the above ...@@ -88,7 +88,8 @@ of parentheses, but will call callables automatically, hiding the above
distinction. distinction.
Be careful with your own custom properties - it is up to you to implement Be careful with your own custom properties - it is up to you to implement
caching. caching when required, for example using the
:class:`~django.utils.functional.cached_property` decorator.
Use the ``with`` template tag Use the ``with`` template tag
----------------------------- -----------------------------
...@@ -111,10 +112,11 @@ For instance: ...@@ -111,10 +112,11 @@ For instance:
* At the most basic level, use :ref:`filter and exclude <queryset-api>` to do * At the most basic level, use :ref:`filter and exclude <queryset-api>` to do
filtering in the database. filtering in the database.
* Use :class:`F expressions <django.db.models.F>` to do filtering * Use :class:`F expressions <django.db.models.F>` to filter
against other fields within the same model. based on other fields within the same model.
* Use :doc:`annotate to do aggregation in the database </topics/db/aggregation>`. * Use :doc:`annotate to do aggregation in the database
</topics/db/aggregation>`.
If these aren't enough to generate the SQL you need: If these aren't enough to generate the SQL you need:
...@@ -233,6 +235,8 @@ queryset``. ...@@ -233,6 +235,8 @@ queryset``.
But: But:
.. _overuse_of_count_and_exists:
Don't overuse ``count()`` and ``exists()`` Don't overuse ``count()`` and ``exists()``
------------------------------------------ ------------------------------------------
......
...@@ -26,6 +26,7 @@ Introductions to all the key parts of Django you'll need to know: ...@@ -26,6 +26,7 @@ Introductions to all the key parts of Django you'll need to know:
pagination pagination
python3 python3
security security
performance
serialization serialization
settings settings
signals signals
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment