本文へ移動
cccskills
無料GitHub で公開日本語紹介

py-code-insight-counters

PyCodeInsightCountersでPython型推論エンジンの処理量をテスト内で数え、変更による作業量や入力サイズに応じた増加を評価します。

原文原文の説明を見る

Count Python code insight work in tests with PyCodeInsightCounters.

JetBrains/intellij-communityスター 20,664(GitHub 20,664 + cccskills 0)

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • 型推論の処理回数を検証したいとき
  • 性能退行をテストで固定したいとき
  • 入力サイズごとの処理量を比べたいとき
  • ハイライト処理を計測したいとき

日本語での紹介

できること

Pythonの型推論エンジンが行う処理を、テスト内で PyCodeInsightCounters により数えます。型取得やキャッシュ、型照合、制御フロー構築などのカウンターを使い、変更前後の作業量や入力規模に応じた増え方を確認できます。PyPerfProbe を使うと、シナリオごとに処理時間、メモリ割り当て、AST読み込みも測定して PYPERF 行として報告できます。時間だけに頼らず、安定した処理回数で性能上の退行をテストに固定する方法も扱います。

こんなときに便利

型エンジンの変更で不要な処理が増えていないか確認したいときや、性能問題を再発防止テストにしたいときに向いています。コード量を変えたときの処理の伸び方を比べたり、ハイライト処理やファイル編集後のシナリオを計測したりする場合にも使えます。

使い方の例

  • 「この型取得処理の評価回数をテストで確認してください」
  • 「入力サイズを変えて型エンジンの処理量を比較してください」
  • 「ハイライト処理の性能シナリオをPyPerfProbeで測定してください」

注意点

カウンターは初期状態では無効です。呼び出しスレッドだけを数える方法と全スレッドのスナップショットでは対象が異なり、全スレッドの差分にはIDEのバックグラウンド処理も含まれます。性能テストは通常のテスト実行ではスキップされます。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(1)

  • SKILL.md4.9 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

<!-- Generated by community/.ai/render-guides.mjs; edit community/.agents/skills/py-code-insight-counters/SKILL.md -->

Python code insight counters

PyCodeInsightCounters (python-psi-impl, package com.jetbrains.python.codeInsight) counts the work of the native Python type engine. PyPerfProbe (community/python/testFramework, package com.intellij.python.community.testFramework.performance) measures a scenario with these counters, the wall time, the allocations and the AST loads.

Use them to show that a change does less work, to show how the work grows with the input, or to pin a performance defect in a test. A work count does not flake like a time.

Counters

CounterCountsHook
GET_TYPE_CALLSeach getType callTypeEvalContextImpl.getType
GET_TYPE_CACHE_HITSthe calls that the context cache answersTypeEvalContextImpl.getType
GET_TYPE_EVALUATIONSthe calls that evaluate a typeTypeEvalContextImpl.getType
CONTEXTS_CONSTRUCTEDeach type context, also the library and assumption contextsTypeEvalContextImpl constructor
CONTEXT_LOOKUP_MISSESthe context lookups that store a new contextTypeEvalContextCacheImpl
ASSUME_TYPE_CALLSthe narrowing assumptions that create a contextTypeEvalContextImpl.assumeType
MATCH_STEPSthe steps of the type matchPyTypeChecker.match
OVERLOAD_CANDIDATES_CHECKEDthe overload candidates that the argument types checkPyCallExpressionHelper.matchesByArgumentTypes
CFG_BUILDS, CFG_INSTRUCTIONSthe control flow builds and their instructionsPyControlFlowBuilder.buildControlFlow

A cache hit and an evaluation do not add up to the calls. The rest are library delegations and the requests that the recursion guard stops.

Count in a test

The counting is off by default. For the work of the calling thread only:

val counts = PyCodeInsightCounters.countOnCurrentThread { context.getType(expression) }
assertEquals(1L, counts.getValue(Counter.GET_TYPE_EVALUATIONS))

The highlighting passes run on other threads, so countOnCurrentThread does not see their work. For all threads, take two snapshots:

PyCodeInsightCounters.enable(testRootDisposable)
val before = PyCodeInsightCounters.snapshot()
myFixture.doHighlighting()
val delta = PyCodeInsightCounters.snapshot() - before
assertTrue(delta[Counter.CFG_BUILDS] >= 1)

The delta also contains the background work of the IDE in that time. Assert an exact count only for the calling thread. Otherwise assert a bound or a ratio.

Measure a scenario

  1. Implement PyPerfProbe.Editor over the test fixture. FixtureEditor in PyNativeEngineCountersPerformanceTest is an example.
  2. Create the probe with a disposable. The probe turns the counting on, turns off the RecursionManager test checks and sets the registry keys of PyPerfProbe.PINNED_REGISTRY to their IDE values.
  3. Call one of these:
    • measure(scenario) { action } runs 3 warm-up attempts and 10 attempts. Before each attempt, setup runs. The default setup is cold().
    • measureEditorFile(name, inspections) measures a cold highlighting, a highlighting after a one-character edit, and one inferAll pass.
    • measureScaled(scenario) { action } uses fewer attempts when the first run takes more than 10 seconds.
  4. Call report(result). It prints PYPERF lines: the time quantiles, the allocations, the AST loads of the first attempt, and each counter with its median, its range and the value of the first attempt.

Mark the test class with @PerformanceUnitTest. The usual test runs skip it. tests.cmd runs it when you give its fully qualified name.

The system property pyperf.out names a file that also gets the PYPERF lines. The system property pyperf.astload.stacks=true prints the stack of the first three AST loads of each file.

Read the result

  • cold() drops the PSI caches and the type contexts. The PSI, the stubs, the control flow and the soft caches stay. So the counts of one scenario change between attempts. For a cold highlighting of pandas_examples.py, the range of type.getType.evaluations is about 20 % of the median.
  • Compare medians, and read the range= value before you claim a difference.
  • For the complexity of an algorithm, measure the input at several sizes (n, 2n, 4n) and compare the growth of a counter. Do not compare single times.

Add a temporary counter

  1. Add an entry to PyCodeInsightCounters.Counter with a stable dotted id, for example type.foo.calls.
  2. At the hook, call PyCodeInsightCounters.inc(Counter.FOO_CALLS) or add(counter, value). When the counting is off, a call costs one volatile read. Put other work at the hook behind PyCodeInsightCounters.isEnabled.
  3. Keep a counter in the merge request only when a test asserts on it. Remove the others before the merge.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

actions

無料概要あり

IntelliJプラグインのAnActionと登録設定を実装・変更し、表示文言やアイコンの定義、非同期処理の起動方法を整えます。

  • IDEに新しいアクションを追加したいとき
  • アクションの登録やアイコンを変更したいとき
  • 表示名と説明文の定義を整理したいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

bazel-test-migration

無料概要あり

IntelliJのJPSテストモジュールをBazelへ移行し、Bazelだけで起きる失敗を依存関係や実行環境から切り分ける手順を案内します。

  • JPSテストをBazelへ移行したいとき
  • Bazelだけで起きるテスト失敗を調べたいとき
  • テストの依存関係やデータ設定を確認したいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

code-style

無料概要あり

IntelliJのKotlin・Javaコードを新規作成やレビューする際に、言語の選び方、書式、型の扱い、例外処理などのプロジェクト規約に沿って整えるスキルです。

  • IntelliJ規約に沿ってKotlinを書きたいとき
  • Javaコードをレビューしたいとき
  • 例外処理やsealed型の分岐を確認したいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

commits

無料概要あり

IntelliJ向けの変更を適切な単位に分け、チケットの有無に応じた形式で、理由や判断も伝わるコミットメッセージを作成・修正するスキルです。

  • チケット付き変更のメッセージを作りたいとき
  • テストやドキュメントのコミットを整理したいとき
  • 既存のコミットメッセージを修正したいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

compare-python-typecheckers

無料概要あり

Pythonコードの型推論や型エラーを複数の型チェッカーで比較し、各ツールの判定と診断内容をまとめたレポートを作成します。

  • 型推論の違いを比較したいとき
  • 型エラーになるか確かめたいとき
  • 複数チェッカーの診断を見比べたいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

compose-ui-architecture

無料概要あり

Compose Desktopの画面で状態や副作用をどこに持たせるか整理し、表示と判断の境界、再利用部品やリストの設計を整えます。

  • 画面とプレゼンターの責務を分けたいとき
  • UI状態の置き場所を整理したいとき
  • Effectやコルーチンの使い方を見直したいとき
JetBrains/intellij-community2.1万2026年10月26日 更新

JetBrains のスキルをすべて見る

このスキルの問題を報告する