Skip to content

Commit

Permalink
fix: Improve SortContent performance on large contracts (#538)
Browse files Browse the repository at this point in the history
Whenever `order_verifiable_content` was called on `interactions` or
`messages` each item was serialized to json multiple times. WIth
`sort_by` each iteam is serialized once.

Flamegraph shows that this change intoduce a drop of SortContent#call
percentage in PactContentDiff.to_text call from 30% to 17%.
  • Loading branch information
barthez authored Dec 23, 2021
1 parent 52efbca commit 1914c01
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pact_broker/pacts/sort_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.order_verifiable_content probably_array
# You never can tell what people will do...
if probably_array.is_a?(Array)
array_with_ordered_hashes = order_hash_keys(probably_array)
array_with_ordered_hashes.sort{ |a, b| a.to_json <=> b.to_json }
array_with_ordered_hashes.sort_by(&:to_json)
else
probably_array
end
Expand Down

0 comments on commit 1914c01

Please sign in to comment.