python / python/cpython

Use saturating counters for branch taken counters in `_POP_JUMP_IF_FALSE` and similar instructions.

Aperta
#151,499 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

interpreter-core performance topic-JIT
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Each conditional branch instruction contains a 16 bit field for recording the direction of the last 16 jumps.

    uint16_t *branches;
    uint16_t val = *branches;
    val = (val << 1) | direction;
    *branches =val;

This tells the direction of the last 16 branches.
When recording traces for the JIT, 16 branches is not a lot of information to guide region selection.

Instead, we could record the count of the two directions instead using a pair of saturating 8 bit counters.

    uint8_t branches[2];
    branches[direction] += (branches[direction] != 255);

Which is only one extra ALU instruction for most C compilers, and no extra memory accesses.

With a JIT warmup of up 500, we can get precise numbers of the branches taken.
With a warmup of a 1000, the saturating counters can still distinguish between branches that are rarely taken and those which are more balanced.

For example, if a branch switches direction every 20 times, the current counter might show a perfectly biased branch, but the saturating counter approach will show that the branch is roughly balanced.

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 dall’istruzione _POP_JUMP_IF_FALSE e da implementazioni simili dei branch condizionali, quindi traccia il modo in cui i relativi dati di branch vengono registrati per le tracce JIT. La modifica è completata quando i conteggi delle direzioni usano due contatori saturanti, sono limitati a 255 e forniscono le informazioni di warmup proposte senza modificare il comportamento dell’istruzione.

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

Valutazione

Stack tecnologico
c, python
Ambito
compilers, performance
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.