perf(npm/csharp): a child chain is derived for every node with a parameter list

オープン 初心者向け
#1,879 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp, rust

調査の方向性

src/metrics/npm/csharp.rs と issue に記載された Java のガードを読み、src/observation_tests.rs の the_member_walks_derive_a_chain_per_body_not_per_node と member_walk_siblings::FIXTURES を調べてください。子チェーンを導出する前に C# のノード種別を確認し、その後、ガードを C# または fixture の行に拡張してください。既存のガードにリグレッションを起こさず、C# の body ごとのカウントが期待される動作と一致すれば完了です。

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

説明

low-priority performance

Summary

C#'s Npm::compute derives a child chain for every node that has a parameter_list child, before it knows the node is a type declaration. A class with 65 methods derives 67 chains where the other languages derive 2.

Measured

Counted with child_chains_derived over Ast::metrics with only Npa and Npm selected, on a class body of 65 units. Measured on the local branch refactor/1871-sibling-followups (not pushed) at e0cc1918, whose base is 68b70b08; the C# code is unchanged from main:

Language Unit Chains derived
Java int x; and void m() {} 2
Kotlin val x = 1 and fun m() {} 2
C++ int x; and void m() {} 2
C# public int x; and void M() {} 67

The fixture table is member_walk_siblings::FIXTURES in src/observation_tests.rs.

Cause

src/metrics/npm/csharp.rs asks the primary-constructor question (#1828) of every node it is handed:

if let Some(list) = node.first_child(|id| id == ParameterList)
    && func_opener::is_callable(&list, code, ancestors.of_children(node).get())

A method_declaration has a parameter_list child, so the chain is derived for each method, then the row's parent gate answers "not under a type declaration" and the chain is dropped.

Cost

One allocation per method, constructor, local function and delegate. A derivation has been one allocation since #1805, so this is a constant factor that the scaling gate cannot price. It is the shape the_member_walks_derive_a_chain_per_body_not_per_node guards for Java only (lesson 103).

Suggested fix

Test the node's kind (the type declarations a primary constructor can sit under) before deriving the chain, or read the parent gate's answer from node itself. Then extend the per-body guard to C#, or to every row of the fixture table above.

Related

#1828, #1805, #1696, #1871.

主要言語
Rust
スター
32
フォーク
3
平均マージ
9時間 55分
マージ済み PR(30日)
102

環境構築

はじめの一歩

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

dekobon/big-code-analysis のほかの issue

dekobon/big-code-analysis の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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