Avoid N+1 calls for image_path when rendering commits
What does this MR do?
When rendering projects/commits/commit
partial, it calls some helper methods like sprite_icon
and clipboard_button
.
These methods call sprite_icon_path
internally which is not that slow (averaging around 6ms per call on my local machine). But when called multiple times (e.g. rendering 100 commits), it adds up. Memoizing the method helps in reducing the number of calls.
Some benchmark numbers for Projects::MergeRequestsController#commits
(average of 5 requests, with RAILS_PROFILE
env var set to true
:
- BEFORE: 1.051528
- AFTER: 0.684848
This shows around 35% improvement.
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
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Patrick Bajao