Speed up the BlameController: view part
What does this MR do?
An attempt to speed up the BlameController.
I found the view code was the biggest offender when I started to profile it locally.
The main idea of the fix is to avoid calculating the same values multiple times (e.g links to sprites), which is very expensive for such a huge page (see the first flamegraph).
On my local env, TTFB reduced from ~40s to ~13s on http://127.0.0.1:3000/root/imported/-/blame/master/locale/gitlab.pot (gitlabhq).
It still slow and could be optimized further, but this small change looks like low hanging fruit™ to me (it's a good start).
What have changed
- Move blame_group render into partial (to reduce the complexity of the original view, don't affect performance)
- Cache sprite_iconandiconcalls - they are the same for every commit inside every blame, it was a huge issue (see the flame graph screenshot).
- Another observation: on gitlabhq, for thelocale/gitlab.potpage, we had~9600blame_groups, having only~1000unique commits in them. That means we could cache everything item generated for each commit (e.g. links).
Screenshots
Flamegraph (view code only) from the master:
Notice 18s (!) being spent in IconsHelper 
--
After moving per-commit precalculation to the presenter (Stackprof wrapped around controller this time, as views are rather trivial now, at least compared with what was before):
--
After moving per-commit precalculation to the presenter (Stackprof wrapped around the view):
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
- 
Code review guidelines 
- 
Merge request performance guidelines 
- 
Style guides 
- [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
N/A
Security
N/A
Related #217572 (closed)
Edited  by 🤖 GitLab Bot 🤖


