perf(context): резолв символов объявления через индекс selection-range#4255
Conversation
SymbolTree.getMethodSymbol(ctx) and getVariableSymbol(ctx) resolved a declaration's symbol with a linear scan over getMethods()/getVariables(), comparing subNameRange/variableNameRange by Range.equals on every element. On a large module (SSL УправлениеДоступомСлужебный, ~48k lines) this is a hot path in ReferenceIndexFiller and the diagnostics engine. Both ranges are exactly the symbol's selectionRange (AbstractMethodSymbol.getSelectionRange()==getSubNameRange(), AbstractVariableSymbol.getSelectionRange()==getVariableNameRange()), so the lookup can reuse the existing O(1) selection-range line index behind findSymbolBySelectionRange(Position) instead of scanning. Measured on the SSL module: CommonModuleAssignDiagnostic 1017ms -> 36.8ms (x27.6), with identical diagnostic output (parity). Adds a focused test covering both context overloads. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01BSiRGLm633B4EmvG3vkk4V
|
Warning Review limit reached
Next review available in: 18 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughSymbolTree now resolves method and variable symbols through the selection-range index instead of scanning symbol collections. Tests locate declaration contexts in the parsed AST and verify both lookups. ChangesSymbol resolution
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Test Results 3 606 files ±0 3 606 suites ±0 1h 42m 34s ⏱️ - 5m 24s For more details on these failures, see this check. Results for commit 00cbd4a. ± Comparison against base commit ccd5156. ♻️ This comment has been updated with latest results. |
The selection-range lookup in getMethodSymbol(ctx)/getVariableSymbol(ctx) returned any symbol whose selectionRange merely *contained* the start of the computed range. The previous linear scan required exact range equality and so returned empty for non-declaration or error contexts (e.g. callers that pass ctx.getParent() or a broken node whose start falls inside a neighbouring symbol's name). Without that guard an extra symbol was resolved — surfacing as CognitiveComplexityCodeLensSupplierTest seeing 3 code lenses instead of 2. Re-add the exact-range equality filter after the O(1) index lookup, keeping the performance win while restoring the prior semantics. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01BSiRGLm633B4EmvG3vkk4V
|


Описание
SymbolTree.getMethodSymbol(ParserRuleContext)иgetVariableSymbol(ParserRuleContext)резолвили символ по месту объявления линейным сканомgetMethods()/getVariables(), сравниваяsubNameRange/variableNameRangeчерезRange.equalsна каждом элементе. На большом модуле (общий модуль SSLУправлениеДоступомСлужебный, ~48k строк) это горячий путь: он вызывается изReferenceIndexFiller(индексация) и движка диагностик.Оба диапазона — это ровно
selectionRangeсимвола:AbstractMethodSymbol.getSelectionRange() == getSubNameRange(),AbstractVariableSymbol.getSelectionRange() == getVariableNameRange().Поэтому поиск переиспользует уже существующий O(1)-индекс селекшн-рейнджей за
findSymbolBySelectionRange(Position)(line-индекс, добавленный ранее в серии), вместо скана.Замеры
На модуле
УправлениеДоступомСлужебный:CommonModuleAssignDiagnosticВывод диагностик идентичен до/после (parity, количество диагностик совпадает).
Связанные задачи
Продолжение серии перф-оптимизаций движка резолюции типов/ссылок (#4249–#4254).
Closes
Чеклист
Общие
SymbolTreeTest.getMethodSymbolAndGetVariableSymbolResolveByDeclarationContext+ сохранён parity в затрагиваемых диагностиках/провайдерах)Дополнительно
Затронуты только два метода
SymbolTree; поведение (первое совпадение по началу имени символа) сохранено. Прогнаны зелёнымиSymbolTreeTest,CommonModuleAssignDiagnosticTest,MissingVariablesDescriptionDiagnosticTest,RenameProviderTest,ReferenceIndexTest,ReferencesProviderTest.Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Tests