Python code insight counters
SkillDev toolsLets your agent count Python type-engine work in IntelliJ tests to catch performance regressions.
Use Python code insight counters in Claude, ChatGPT or Ahel Desktop
Free. Sign in, add Python code insight counters and connect your AI. About a minute.
Also: Claude Code · Cursor · Codex
Then ask your AI: use the Python code insight counters skill
Details
Instructions available. Your AI can read the instructions. Execution depends on the setup they require.
Account requirements not reviewed. Check the skill instructions before use; ahel provides instructions and does not run this skill.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
About this skill
Count Python code insight work in tests with PyCodeInsightCounters.
What this skill tells your AI
The instructions your AI receives, as published by jetbrains/intellij-community in .agents/skills/py-code-insight-counters/SKILL.md and read by ahel’s review.
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
| Counter | Counts | Hook |
|---|---|---|
GET_TYPE_CALLS | each getType call | TypeEvalContextImpl.getType |
GET_TYPE_CACHE_HITS | the calls that the context cache answers | TypeEvalContextImpl.getType |
GET_TYPE_EVALUATIONS | the calls that evaluate a type | TypeEvalContextImpl.getType |
CONTEXTS_CONSTRUCTED | each type context, also the library and assumption contexts | TypeEvalContextImpl constructor |
CONTEXT_LOOKUP_MISSES | the context lookups that store a new context | TypeEvalContextCacheImpl |
ASSUME_TYPE_CALLS | the narrowing assumptions that create a context | TypeEvalContextImpl.assumeType |
MATCH_STEPS | the steps of the type match | PyTypeChecker.match |
OVERLOAD_CANDIDATES_CHECKED | the overload candidates that the argument types check | PyCallExpressionHelper.matchesByArgumentTypes |
CFG_BUILDS, CFG_INSTRUCTIONS | the control flow builds and their instructions | PyControlFlowBuilder.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
- Implement
PyPerfProbe.Editorover the test fixture.FixtureEditorinPyNativeEngineCountersPerformanceTestis an example. - Create the probe with a disposable. The probe turns the counting on, turns off the
RecursionManagertest checks and sets the registry keys ofPyPerfProbe.PINNED_REGISTRYto their IDE values. - Call one of these:
measure(scenario) { action }runs 3 warm-up attempts and 10 attempts. Before each attempt,setupruns. The defaultsetupiscold().measureEditorFile(name, inspections)measures a cold highlighting, a highlighting after a one-character edit, and oneinferAllpass.measureScaled(scenario) { action }uses fewer attempts when the first run takes more than 10 seconds.
- Call
report(result). It printsPYPERFlines: 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 ofpandas_examples.py, the range oftype.getType.evaluationsis 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
- Add an entry to
PyCodeInsightCounters.Counterwith a stable dotted id, for exampletype.foo.calls. - At the hook, call
PyCodeInsightCounters.inc(Counter.FOO_CALLS)oradd(counter, value). When the counting is off, a call costs one volatile read. Put other work at the hook behindPyCodeInsightCounters.isEnabled. - Keep a counter in the merge request only when a test asserts on it. Remove the others before the merge.
Signals
- GitHub stars
- 21k
- Forks
- 6k
- Last commit
- Sep 2026
Advanced
- Item type
- skill
- Key
py-code-insight-counters- Source
- github.com/jetbrains/intellij-community
github.com/jetbrains/intellij-community
Related picks
Skill · kotlin
The pick for Kotlinapollo-kotlin
Skill · apollographql
The pick for Kotlinpython-performance-optimization
Skill · wshobson
The pick for Pythonpython-pro
Skill · jeffallan
The pick for Pythonpandas-dataframe-analyzer
Skill · a5c-ai
The pick for Pandasxlsx
Skill · anthropics
The pick for Pandas