Skip to content

[Request] Could importing asyncio optional? #765

@methane

Description

@methane

After #731 is merged, importing jinja2 on Python 3 get dramatically faster.
For now, over 40% of import time is caused by asyncio support.

      - asyncio 36.123 [ms]
    - jinja2.asyncsupport 36.397 [ms]
    - jinja2.asyncfilters 0.297 [ms]
  - jinja2 84.312 [ms]

(See this gist for detail)

Jinja2's document says:

First you need to be aware that by default async support is disabled as enabling it will generate different template code behind the scenes which passes everything through the asyncio event loop.

But even when user doesn't use async support, jinja2.asyncsupport is imported:

jinja/jinja2/__init__.py

Lines 74 to 82 in b73cb48

def _patch_async():
from jinja2.utils import have_async_gen
if have_async_gen:
from jinja2.asyncsupport import patch_all
patch_all()
_patch_async()
del _patch_async

Would you make importing asyncio optional to improve import time of jinja2?

For example, faster import time is beneficial on GAE/Python.
And less import means less memory footprint too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions