From 1914c01f7523bdd661ff772b9b0f2bc7a85f55f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Bu=C5=82at?= Date: Thu, 23 Dec 2021 23:11:22 +0100 Subject: [PATCH] fix: Improve SortContent performance on large contracts (#538) 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%. --- lib/pact_broker/pacts/sort_content.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pact_broker/pacts/sort_content.rb b/lib/pact_broker/pacts/sort_content.rb index 47a0b5418..702c34da4 100644 --- a/lib/pact_broker/pacts/sort_content.rb +++ b/lib/pact_broker/pacts/sort_content.rb @@ -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