New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Could importing asyncio optional? #765

Closed
methane opened this Issue Sep 6, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@methane
Contributor

methane commented Sep 6, 2017

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.

@cooperlees

This comment has been minimized.

cooperlees commented Feb 4, 2018

Can we also look at exempting the Py3 only .py files from the Py2 wheel?

When I build pex's I also compile all .py files into .pycs and even tho 'async.*.py' files are not imported in Python2 I have issues due to the Py3 only source file existing in the Py2 wheel and trying to be compiled with 2.7.

I can have a go at a PR - Anyone got good ideas about how to do this?

@methane

This comment has been minimized.

Contributor

methane commented Feb 5, 2018

Including Py3 only source in universal wheel or source package is very common.
I think pex must fix it. I don't think every package should change their package for pex.

Anyway, it's not relating to this issue.

@davidism

This comment has been minimized.

Member

davidism commented Feb 5, 2018

This had been discussed multiple times. I'm on my phone, so can't link right now. Our stance is that if a build tool fails on files that won't be imported on unsupported versions, it's the build tool that needs to be fixed.

methane added a commit to methane/jinja that referenced this issue Feb 6, 2018

@davidism davidism added this to the 2.11 milestone Feb 6, 2018

@davidism davidism closed this in #806 Feb 6, 2018

asenov added a commit to asenov/jinja that referenced this issue Feb 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment