python / python/cpython

Windows build importlib performance regression

Aperta
#99,858 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic-importlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Descrizione

Bug report

I've a file import_models.py:

import time
from ctypes import c_longdouble
from multiprocessing import Value


def import_models_func(_, import_value, exec_value):
    init = time.process_time()
    import some_class
    import_value.value = time.process_time() - init
    exec_value.value = 0


if __name__ == '__main__':
    import_models_func(0, Value(c_longdouble, lock=False), Value(c_longdouble, lock=False))

The some_class.py is:

import time


class SomeClass:
    __slots__ = ('a', 'b', 'c')

    def __init__(self):
        self.a = time.time()
        self.b = self.a / 100
        self.c = self.b ** 2

    B = 2
    for _ in range(10):
        B **= 2

    @property
    def a_val(self):
        return self.a

    @a_val.getter
    def a_val(self):
        return self.a

    @property
    def b_val(self):
        return self.b

    @b_val.getter
    def b_val(self):
        return self.b

    @property
    def c_val(self):
        return self.c

    @c_val.getter
    def c_val(self):
        return self.c

The directory containing both files has no __pycache__. I run python -X importtime import_models.py and receive:

import time:       521 |        521 | some_class

Then I run python -m compileall . and re-run the command above, the output is:

import time:       548 |        548 | some_class

I've tried the sampling with multiprocessing governor, which is run with -B. The governor runs this scenario for 100 times, both mean and median statistics values of the timing measured mostly provide with the same results: the timing without __pycache__ is less than when the source files are pre-compiled. Which is a non-sense keeping in mind what the pre-compiled byte-code cache is built for.

I've searched for Windows-related fixes through the versions 3.9 to 3.12 and found nothing about this regression.

Linux build in a native (non-WSL, non-emulated) environment does not have such an issue (the bytecode-compiled version gets imported faster, up to 10 times, than a raw non-compiled source)

Your environment

  • CPython versions tested on: Python 3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)] on win32
  • Operating system and architecture: Windows 10 Enterprise 21H2 19044.2251

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo la differenza nei tempi su Windows 10 con i file forniti import_models.py e some_class.py usando -X importtime, quindi confronta le esecuzioni prima e dopo python -m compileall . e con -B. Controlla i percorsi di importazione di importlib e specifici di Windows coinvolti nel caricamento del modulo. Il lavoro è completo quando viene identificata la causa dell’importazione in cache più lenta e la regressione viene documentata o corretta con un confronto verificato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
operating-systems, performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.