Commit 7e7a4b54 authored by Tan Le's avatar Tan Le

Reduce object allocations for large merge request

This MR replaces hash array syntax with `each_with_object` to create a
hash of commits. This approach avoids a large number of object
allocations.
parent 732d2823
......@@ -86,9 +86,9 @@ class CommitCollection
# Batch load full Commits from the repository
# and map to a Hash of id => Commit
replacements = Hash[unenriched.map do |c|
[c.id, Commit.lazy(container, c.id)]
end.compact]
replacements = unenriched.each_with_object({}) do |c, result|
result[c.id] = Commit.lazy(container, c.id)
end.compact
# Replace the commits, keeping the same order
@commits = @commits.map do |original_commit|
......
---
title: Reduce object allocations for large merge request
merge_request: 49563
author:
type: performance
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment