Skip to content

Improve BlobController show.json performance: cache method calls

Aleksei Lipniagov requested to merge 217580-improve-blob-show-performance into master

What does this MR do?

A (possible) set of "low hanging fruit improvements".

I mostly tested it on gitlabhq/-/blob/master/CHANGELOG.md locally, as I found it to be "appropriately" slow to work from there. It takes ~40 seconds locally.

1. Avoid Project.markdown_reference_pattern repeated call?

Looking into the flame graph, it would allow us to save ~3 seconds, as it is called in the cycle:
Screenshot_2020-06-04_at_19.16.36

After caching the value, we see that Banzai::Filter::ProjectReferenceFilter#call is faster now:

Screenshot_2020-06-04_at_20.23.26

2. The same is for User.reference_pattern

(check the screenshot above)


Maybe we should deal with class methods that only generate strings through all the codebase?
Seems that we have quite a few of those, especially regexes.
It could be caching or moving them into const.
We could also create a rubocop's cop which checks that.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

N/A

Security

N/A

Related to #217580 (closed)

Edited by Sean Carroll

Merge request reports