JIT: Interprocedural analysis for out parameters

Aperta
#138,133 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
12/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
compilers

Direzione di ricerca

This is open-ended JIT design work: the body asks whether to compile specialized versions of methods with out parameters or to strengthen the inliner, and names no file. Start by reading the linked PR 138016 to see the local-variable rewrite it used, and the JIT inliner sources under src/coreclr/jit. Done means a design agreed with the JIT maintainers (@jkotas, @dotnet/jit-contrib), not a patch.

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

Descrizione

area-CodeGen-coreclr untriaged

It seems that in the vast majority of calls with out parameters, callers declare the corresponding arguments inline:

void Foo(..., out int written)
{
    ...
    written++;
    ...
    written++;
}

// typical usage
Foo(..., out int written);

Knowing that an out argument is on the stack and is not aliased can help the JIT generate better code. For example, https://github.com/dotnet/runtime/pull/138016 made one benchmark nearly 2.5x faster by updating a local variable instead of modifying the out argument directly.

Suggestion

Could we compile two versions of each method with out parameters: a default version and a specialized version that uses this hint? The JIT could then choose the appropriate version at each call site. The ReJIT concern still applies, but is there anything else I'm missing?

Alternatively, we can boost the inliner additionally.

cc @jkotas @dotnet/jit-contrib

Data

Roslyn syntax scan over the product code in src/libraries and src/coreclr/System.Private.CoreLib, excluding tests and ref folders (12,463 files, 15,780 out arguments at call sites):

out argument kind Share
inline decl (out var x / out T x) 37.4%
pre-declared local 26.6%
forwarded out param (TryX -> TryXCore) 23.4%
discard (out _ / out var _) 7.2%
field / this.x / arr[i] / *p / ref param / other 5.4%

Inline declarations are about 37%. All non-aliased stack locals (inline + pre-declared + discard) add up to about 71%.

Lingua principale
C#
Stelle
18.5k
Fork
5.8k
Merge medio
2g 18h
PR unite (30g)
588

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

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.

Altre issue di dotnet/runtime

Tutte le issue di dotnet/runtime

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.