实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。
- 为 IDE 菜单添加操作
- 修改操作注册或图标
- 整理操作名称和说明
在测试中用 PyCodeInsightCounters 统计 Python 类型推断引擎的工作量,并通过 PyPerfProbe 比较操作次数、内存分配、AST 加载和耗时,以评估性能变化或回归。
Count Python code insight work in tests with PyCodeInsightCounters.
实测评分 未实测
查看安装方法本技能介绍如何在测试中使用 PyCodeInsightCounters 统计 Python 类型推断引擎执行的工作。计数器涵盖类型获取、缓存、类型匹配和控制流构建,可用于比较修改前后的工作量,或观察工作量如何随输入规模变化。使用 PyPerfProbe 时,还可以测量不同场景的耗时、内存分配和 AST 加载,并以 PYPERF 行报告。技能也说明如何通过稳定的操作计数编写性能回归测试,避免只依赖可能波动的运行时间。
当您想确认类型引擎的修改是否增加了不必要的工作,或想把性能问题固定为回归测试时,可以使用本技能。它也适用于比较代码量变化后的工作量增长,以及测量代码高亮或文件编辑后的处理场景。
计数器默认处于关闭状态。countOnCurrentThread 只统计调用线程;对所有线程做快照时,差值也会包含 IDE 的后台工作。性能测试在普通测试运行中会被跳过。
本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。
AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。
不计入评分。 由 AI(OpenAI Codex)于 2026年10月28日 评估。仅供参考,安装前请同时查看原文。
安装前可以查看交给 AI 代理的指令内容。
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.
| 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.
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.
PyPerfProbe.Editor over the test fixture. FixtureEditor in PyNativeEngineCountersPerformanceTest is
an example.RecursionManager test checks and
sets the registry keys of PyPerfProbe.PINNED_REGISTRY to their IDE values.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.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.
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.range= value before you claim a difference.PyCodeInsightCounters.Counter with a stable dotted id, for example type.foo.calls.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.还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。
将 IntelliJ JPS 测试模块迁移到 Bazel,并排查仅在 Bazel 中出现的失败。根据症状检查依赖、插件、测试数据和 runfiles,重新生成并验证目标。
按 IntelliJ 项目规范编写或审查 Kotlin 和 Java 代码,涵盖语言选择、格式、密封类型、线程注解及控制流异常处理。
本指南帮助您按 IntelliJ 项目规则拆分更改并撰写提交信息:有工单时使用编号和变更说明,无工单时使用标签与子系统名,并在需要时说明原因和决定。
使用多个 Python 类型检查器比较代码片段或文件的类型推断和报错判断,并汇总各工具的结论、耗时与诊断信息,可保存为 Markdown 报告。
整理 Compose Desktop 界面中的状态和副作用,让可组合函数负责绘制,由展示器或协调器处理应用决策。了解状态归属、Effect、可复用组件接口、延迟列表键、动画和性能,适用于单项界面修改。