Skip to content

perf(references): слить Location в SymbolOccurrence (−~85 МиБ)#4270

Merged
nixel2007 merged 1 commit into
developfrom
perf/flatten-location-into-occurrence
Jul 15, 2026
Merged

perf(references): слить Location в SymbolOccurrence (−~85 МиБ)#4270
nixel2007 merged 1 commit into
developfrom
perf/flatten-location-into-occurrence

Conversation

@nixel2007

@nixel2007 nixel2007 commented Jul 14, 2026

Copy link
Copy Markdown
Member

Финальный шаг уплотнения reference-индекса поверх #4272 (уже в develop). База PR — develop.

Что и зачем

Раньше на каждое вхождение приходилось два объекта:

SymbolOccurrence{ occurrenceType, symbol, location } ──► Location{ uri, startLine, startChar, endLine, endChar }

URI шарится (~32k экземпляров на 5.98M вхождений), поэтому сам URI — не проблема. Проблема — обёртка Location: отдельный заголовок объекта и лишний прыжок по указателю на каждое из 5.98M вхождений.

Что сделано

Поля Location расплющены прямо в запись SymbolOccurrence, класс references.model.Location удалён:

public record SymbolOccurrence(
  OccurrenceType occurrenceType, Symbol symbol,
  URI uri, int startLine, int startCharacter, int endLine, int endCharacter
) implements Comparable<SymbolOccurrence> { ... }

Blast-radius маленький и механический (не путать с lsp4j org.eclipse.lsp4j.Location, которого правки не касаются): конструирование нашего Location было в 3 местах (ReferenceIndex), чтение через .location().x() — в LocationRepository, MissingCommonModuleMethodDiagnostic и тестах; всё переведено на плоские поля.

Замер на реальном cpm

populateContext по cpm обеими сборками (единственное отличие — плоская запись против записи с обёрткой Location), retained heap после серии System.gc(), две пары прогонов base/flatten вперемежку:

прогон develop (#4272, вхождение + Location) этот PR (плоское вхождение) Δ
раунд 1 1949 МиБ 1873 МиБ −76 МиБ
раунд 2 2050 МиБ 1954 МиБ −96 МиБ

Память: ≈ −85 МиБ реального heap. Абсолютные значения плывут от загрузки машины (раунд 2 шёл под нагрузкой), но контролируемое сравнение — дельта base→flatten внутри раунда — стабильно −76…−96 МиБ. Время построения индекса — без изменений (populate парсинг-bound; разброс времени в прогонах — машинный шум, не эффект правки).

Это меньше исходной оценки −130…145 МиБ, потому что та была HPROF-shallow (ссылки по 8 Б), а реальный heap с compressed oops — 4 Б.

Тестирование

SymbolOccurrenceRepositoryTest (14, тест из #4272 переведён на SymbolOccurrence.of), ReferenceIndexTest (12), LocationRepositoryTest (3) — зелёные, полный compile main+test проходит. Остальное — CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_017AZeyPcsbdUBaLUGWbhrCi

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b397feec-1144-419f-a676-d5f5a90599f9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/flatten-location-into-occurrence

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 14, 2026

Copy link
Copy Markdown
Contributor

Test Results

 3 636 files  ±0   3 636 suites  ±0   1h 36m 44s ⏱️ - 19m 50s
 3 593 tests ±0   3 575 ✅ ±0   18 💤 ±0  0 ❌ ±0 
21 558 runs  ±0  21 446 ✅ ±0  112 💤 ±0  0 ❌ ±0 

Results for commit d12f131. ± Comparison against base commit f1340fa.

♻️ This comment has been updated with latest results.

@sonarqubecloud

Copy link
Copy Markdown

Расплющивает поля `Location` (uri + координаты диапазона) прямо в запись
`SymbolOccurrence` и удаляет класс `Location`. Раньше на каждое вхождение
приходилось два объекта — `SymbolOccurrence` и `Location`; обёртка `Location`
давала лишний заголовок объекта (16 Б) и прыжок по указателю на каждое из
миллионов вхождений. `URI` шарится, поэтому размножается только сама запись.

Диапазон/позиция строятся на лету (`SymbolOccurrence.range()`,
`startPosition()`); фабрика `SymbolOccurrence.of(type, symbol, uri, range)`
скрывает раскладку `Range` в четыре int. Компаратор сравнивает те же поля
напрямую (вложенный `Location`-компаратор убран, порядок идентичен).

Blast-radius маленький: наш `references.model.Location` конструировался в 3
местах и читался через `.location()` в ~10 точках (не путать с lsp4j
`Location`, которого правки не касаются).

Ожидаемая экономия на cpm (5.98M вхождений): уходит ~228 МиБ объектов
`Location`, `SymbolOccurrence` прибавляет ~96 МиБ → нетто ~-130..145 МиБ
(HPROF-shallow). Точная цифра — контрольным дампом.

ReferenceIndexTest + LocationRepositoryTest: 33/33 зелёные.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_017AZeyPcsbdUBaLUGWbhrCi
@nixel2007
nixel2007 force-pushed the perf/flatten-location-into-occurrence branch from d12f131 to 9e39a42 Compare July 15, 2026 10:26
@nixel2007
nixel2007 changed the base branch from perf/reference-index-compact-storage to develop July 15, 2026 10:27
@nixel2007 nixel2007 changed the title perf(references): слить Location в SymbolOccurrence (−~130 МиБ, stacked на #4269) perf(references): слить Location в SymbolOccurrence (−~85 МиБ) Jul 15, 2026
@nixel2007
nixel2007 merged commit 39757fd into develop Jul 15, 2026
15 checks passed
@nixel2007
nixel2007 deleted the perf/flatten-location-into-occurrence branch July 15, 2026 11:28
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.

1 participant