JIT: Interprocedural analysis for out parameters

オープン
#138,133 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
12/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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%.

主要言語
C#
スター
18.5k
フォーク
5.8k
平均マージ
2日 18時間
マージ済み PR(30日)
588

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/runtime のほかの issue

dotnet/runtime の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。