Skip to content

perf(context): резолв символов объявления через индекс selection-range#4255

Merged
nixel2007 merged 2 commits into
developfrom
claude/perf-symboltree-selectionrange-lookup
Jul 10, 2026
Merged

perf(context): резолв символов объявления через индекс selection-range#4255
nixel2007 merged 2 commits into
developfrom
claude/perf-symboltree-selectionrange-lookup

Conversation

@nixel2007

@nixel2007 nixel2007 commented Jul 10, 2026

Copy link
Copy Markdown
Member

Описание

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 1017 ms 36.8 ms (×27.6)

Вывод диагностик идентичен до/после (parity, количество диагностик совпадает).

Связанные задачи

Продолжение серии перф-оптимизаций движка резолюции типов/ссылок (#4249#4254).

Closes

Чеклист

Общие

  • Ветка PR обновлена из develop
  • Отладочные, закомментированные и прочие, не имеющие смысла участки кода удалены
  • Изменения покрыты тестами (SymbolTreeTest.getMethodSymbolAndGetVariableSymbolResolveByDeclarationContext + сохранён parity в затрагиваемых диагностиках/провайдерах)

Дополнительно

Затронуты только два метода SymbolTree; поведение (первое совпадение по началу имени символа) сохранено. Прогнаны зелёными SymbolTreeTest, CommonModuleAssignDiagnosticTest, MissingVariablesDescriptionDiagnosticTest, RenameProviderTest, ReferenceIndexTest, ReferencesProviderTest.


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved resolution of method and variable symbols from their declaration context.
    • Symbol lookups now return the correct declaration more reliably, including when multiple symbols share the same source line.
  • Tests

    • Added coverage validating method and variable resolution from parsed declaration contexts.

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
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@nixel2007, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06104dbe-bcaa-47e3-a3cf-453591c644fd

📥 Commits

Reviewing files that changed from the base of the PR and between 00cbd4a and 7f87dba.

📒 Files selected for processing (1)
  • src/main/java/com/github/_1c_syntax/bsl/languageserver/context/symbol/SymbolTree.java
📝 Walkthrough

Walkthrough

SymbolTree 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.

Changes

Symbol resolution

Layer / File(s) Summary
Indexed declaration lookup
src/main/java/.../context/symbol/SymbolTree.java, src/test/java/.../context/symbol/SymbolTreeTest.java
Method and variable lookups use indexed selection-range positions, filter by symbol type, and are tested against parser declaration contexts.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Название кратко и точно отражает основное изменение: ускорение резолва символов объявления через индекс selection-range.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/perf-symboltree-selectionrange-lookup

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Test Results

 3 606 files  ±0   3 606 suites  ±0   1h 42m 34s ⏱️ - 5m 24s
 3 568 tests +1   3 549 ✅ ±0   18 💤 ±0  1 ❌ +1 
21 408 runs  +6  21 290 ✅ ±0  112 💤 ±0  6 ❌ +6 

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
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

@nixel2007
nixel2007 merged commit bf1cb4e into develop Jul 10, 2026
34 of 35 checks passed
@nixel2007
nixel2007 deleted the claude/perf-symboltree-selectionrange-lookup branch July 10, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants