Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PYTHON_LAZY_IMPORTS=none ignored for__lazy_modules__ #146369

Open
Labels
@hugovk

Description

@hugovk

Bug report

Bug description:

Keyword

Given lazykeyword imports:

lazyimportasynciolazyimportdoctestlazyimportimapliblazyimportjsonlazyimportsmtpliblazyimportunittestlazyimporturllib.requestlazyfromargparseimportArgumentParserlazyfromcollectionsimportOrderedDictlazyfrompathlibimportPath

Then running with-X lazy_imports=none andPYTHON_LAZY_IMPORTS=none will disable lazy imports, as expected:

hyperfine --warmup 10 --runs 20 \   "./python.exe lazy-eager.py" \   "PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-eager.py" \   "PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-eager.py" \   "PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-eager.py" \   "./python.exe -X lazy_imports=normal lazy-eager.py" \   "./python.exe -X lazy_imports=none   lazy-eager.py" \   "./python.exe -X lazy_imports=all    lazy-eager.py"Benchmark 1: ./python.exe lazy-eager.py  Time (mean ± σ):      17.1 ms ±   0.5 ms    [User: 13.2 ms, System: 3.0 ms]  Range (min … max):    16.2 ms …  17.9 ms    20 runsBenchmark 2: PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-eager.py  Time (mean ± σ):      17.2 ms ±   0.4 ms    [User: 13.2 ms, System: 3.1 ms]  Range (min … max):    16.5 ms …  17.9 ms    20 runsBenchmark 3: PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-eager.py  Time (mean ± σ):     141.5 ms ±  11.5 ms    [User: 122.0 ms, System: 16.2 ms]  Range (min … max):   134.8 ms … 184.1 ms    20 runs  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.Benchmark 4: PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-eager.py  Time (mean ± σ):      17.1 ms ±   0.6 ms    [User: 13.2 ms, System: 3.0 ms]  Range (min … max):    16.1 ms …  18.3 ms    20 runsBenchmark 5: ./python.exe -X lazy_imports=normal lazy-eager.py  Time (mean ± σ):      17.2 ms ±   0.5 ms    [User: 13.2 ms, System: 3.1 ms]  Range (min … max):    16.6 ms …  18.2 ms    20 runsBenchmark 6: ./python.exe -X lazy_imports=none   lazy-eager.py  Time (mean ± σ):     136.4 ms ±   1.5 ms    [User: 119.3 ms, System: 15.5 ms]  Range (min … max):   133.4 ms … 138.9 ms    20 runsBenchmark 7: ./python.exe -X lazy_imports=all    lazy-eager.py  Time (mean ± σ):      17.3 ms ±   0.5 ms    [User: 13.3 ms, System: 3.1 ms]  Range (min … max):    16.5 ms …  18.2 ms    20 runsSummary  PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-eager.py ran    1.00 ± 0.05 times faster than ./python.exe lazy-eager.py    1.01 ± 0.04 times faster than PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-eager.py    1.01 ± 0.05 times faster than ./python.exe -X lazy_imports=normal lazy-eager.py    1.01 ± 0.05 times faster than ./python.exe -X lazy_imports=all    lazy-eager.py    7.99 ± 0.30 times faster than ./python.exe -X lazy_imports=none   lazy-eager.py    8.29 ± 0.74 times faster than PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-eager.py

Dunder

But when using__lazy_modules__ instead:

__lazy_modules__= ["argparse","asyncio","collections","doctest","imaplib","json","pathlib","smtplib","unittest","urllib.request",]importasyncioimportdoctestimportimaplibimportjsonimportsmtplibimportunittestimporturllib.requestfromargparseimportArgumentParserfromcollectionsimportOrderedDictfrompathlibimportPath

-X lazy_imports=none andPYTHON_LAZY_IMPORTS=none are ignored and they're lazily imported:

hyperfine --warmup 10 --runs 20 \   "./python.exe lazy-dunder.py" \   "PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-dunder.py" \   "PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-dunder.py" \   "PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-dunder.py" \   "./python.exe -X lazy_imports=normal lazy-dunder.py" \   "./python.exe -X lazy_imports=none   lazy-dunder.py" \   "./python.exe -X lazy_imports=all    lazy-dunder.py"Benchmark 1: ./python.exe lazy-dunder.py  Time (mean ± σ):      17.0 ms ±   0.5 ms    [User: 13.1 ms, System: 3.1 ms]  Range (min … max):    16.3 ms …  18.4 ms    20 runsBenchmark 2: PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-dunder.py  Time (mean ± σ):      16.6 ms ±   0.5 ms    [User: 13.1 ms, System: 2.8 ms]  Range (min … max):    15.9 ms …  17.6 ms    20 runsBenchmark 3: PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-dunder.py  Time (mean ± σ):      16.9 ms ±   0.5 ms    [User: 13.1 ms, System: 3.0 ms]  Range (min … max):    15.7 ms …  17.6 ms    20 runsBenchmark 4: PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-dunder.py  Time (mean ± σ):      16.9 ms ±   0.4 ms    [User: 13.1 ms, System: 3.0 ms]  Range (min … max):    16.3 ms …  17.5 ms    20 runsBenchmark 5: ./python.exe -X lazy_imports=normal lazy-dunder.py  Time (mean ± σ):      17.0 ms ±   0.4 ms    [User: 13.1 ms, System: 3.0 ms]  Range (min … max):    15.9 ms …  17.7 ms    20 runsBenchmark 6: ./python.exe -X lazy_imports=none   lazy-dunder.py  Time (mean ± σ):      16.8 ms ±   0.5 ms    [User: 13.1 ms, System: 2.9 ms]  Range (min … max):    16.1 ms …  17.8 ms    20 runsBenchmark 7: ./python.exe -X lazy_imports=all    lazy-dunder.py  Time (mean ± σ):      16.9 ms ±   0.4 ms    [User: 13.1 ms, System: 3.0 ms]  Range (min … max):    16.5 ms …  17.9 ms    20 runsSummary  PYTHON_LAZY_IMPORTS=normal ./python.exe lazy-dunder.py ran    1.01 ± 0.04 times faster than ./python.exe -X lazy_imports=none   lazy-dunder.py    1.01 ± 0.04 times faster than PYTHON_LAZY_IMPORTS=none   ./python.exe lazy-dunder.py    1.02 ± 0.04 times faster than PYTHON_LAZY_IMPORTS=all    ./python.exe lazy-dunder.py    1.02 ± 0.04 times faster than ./python.exe -X lazy_imports=all    lazy-dunder.py    1.02 ± 0.04 times faster than ./python.exe -X lazy_imports=normal lazy-dunder.py    1.02 ± 0.04 times faster than ./python.exe lazy-dunder.py

Thanks

To@henryiii for discovering this.

CPython versions tested on:

CPython main branch, 3.15

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp