Loading
Memoize dependency linker selection per highlighter
What does this MR do and why?
Problem
Reused highlighters repeatedly select a dependency linker for the same blob path, including repeating negative lookups for unsupported paths.
Solution
- Add an optional preselected linker to
Gitlab::DependencyLinker.link. - Memoize linker selection, including
nil, perGitlab::Highlight. - Pass the memoized linker to each operation while preserving metrics.
- Cover selection, nil caching, per-call metrics, and bypass behavior.
Performance summary
Negative differences indicate improvement.
| Scenario | Metric | Baseline | Solution | Difference |
|---|---|---|---|---|
| Unsupported diff, 100 lines | CPU median | 15.308 ms | 11.142 ms | -27.21% |
| Allocations median | 28,862 | 25,543 | -11.50% | |
| RSS delta median | 6,720 KiB | 6,720 KiB | 0.00% | |
| Unsupported diff, 2,000 lines | CPU median | 168.122 ms | 87.541 ms | -47.93% |
| Allocations median | 349,526 | 266,294 | -23.81% | |
| RSS delta median | 18,456 KiB | 18,456 KiB | 0.00% | |
| Supported Gemfile diff, 100 lines | CPU median | 36.138 ms | 36.218 ms | +0.22% |
| Allocations median | 108,300 | 107,686 | -0.57% | |
| RSS delta median | 13,304 KiB | 13,320 KiB | +0.12% | |
| Supported Gemfile diff, 2,000 lines | CPU median | 832.425 ms | 821.423 ms | -1.32% |
| Allocations median | 1,922,305 | 1,907,987 | -0.74% | |
| RSS delta median | 44,216 KiB | 44,544 KiB | +0.74% | |
| Unsupported small Ruby blob, 20 runs | CPU median | 74.135 ms | 74.842 ms | +0.95% |
| Allocations median | 195,974 | 196,754 | +0.40% | |
| RSS delta median | 18,352 KiB | 18,360 KiB | +0.04% | |
| Unsupported large Ruby blob, 10 runs | CPU median | 615.583 ms | 614.510 ms | -0.17% |
| Allocations median | 1,605,149 | 1,604,367 | -0.05% | |
| RSS delta median | 61,312 KiB | 61,296 KiB | -0.03% | |
| Supported package.json blob, 10 runs | CPU median | 643.159 ms | 643.273 ms | +0.02% |
| Allocations median | 4,223,922 | 4,223,216 | -0.02% | |
| RSS delta median | 91,552 KiB | 91,304 KiB | -0.27% |
How to set up and validate locally
- Run the focused RSpec files:
bin/rspec spec/lib/gitlab/highlight_spec.rb spec/lib/gitlab/dependency_linker_spec.rb - Run RuboCop for the changed files:
bundle exec rubocop lib/gitlab/highlight.rb lib/gitlab/dependency_linker.rb \ spec/lib/gitlab/highlight_spec.rb spec/lib/gitlab/dependency_linker_spec.rb
MR acceptance checklist
This MR has no UI, database, security, authentication, API, migration, translation, or feature-flag changes. It adds focused backend specs for the memoization and metric behavior.
Edited by Vasilii Iakliushin