Skip to content

Avoid N+1 calls for image_path when rendering commits

Patrick Bajao requested to merge 209912-memoize-sprites-icon-path into master

What does this MR do?

When rendering projects/commits/commit partial, it calls some helper methods like sprite_icon and clipboard_button.

sprite-profile

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

Availability and Testing

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

#209912

Edited by Patrick Bajao

Merge request reports