From aff408603b3db5b7974c522db2ad8c5ce2a0f3c1 Mon Sep 17 00:00:00 2001 From: Etienne Pierre-doray Date: Tue, 14 Sep 2021 17:31:51 +0000 Subject: [zucchini]: Convert TargetPool to deque. shrink_to_fit with vector tends to cause high memory peak. Changing deque is a simple change that reduces memory peak at the cost of loss of guarantee (contiguous storage). Similar to https://chromium-review.googlesource.com/c/chromium/src/+/2830864 which dramatically reduced crach rate https://crash.corp.google.com/browse?q=product_name%3D%27Chrome%27+AND+EXISTS+%28SELECT+1+FROM+UNNEST%28CrashedStackTrace.StackFrame%29+WHERE+FunctionName%3D%27installer%3A%3AArchivePatchHelper%3A%3AZucchiniEnsemblePatch%27%29+AND+expanded_custom_data.ChromeCrashProto.magic_signature_1.name%3D%27%5BOut+of+Memory%5D+zucchini%3A%3ADisassemblerWin32%3Czucchini%3A%3AWin32X64Traits%3E%3A%3AParseAndStoreRel32%27 An alternative is to look ahead to determine vector size. The is hard to do with SortAndUniquify, which performs in-place modifications. Bug: 1247633 Change-Id: I624c360ee1f2bf18bd584d1aafdde0f0c2ffb61e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3149810 Commit-Queue: Etienne Pierre-Doray Reviewed-by: Samuel Huang Cr-Commit-Position: refs/heads/main@{#921292} NOKEYCHECK=True GitOrigin-RevId: 380557e6b592531eb360513791968dd7ab0ee77d --- target_pool.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'target_pool.h') diff --git a/target_pool.h b/target_pool.h index 27884d6..fb462b2 100644 --- a/target_pool.h +++ b/target_pool.h @@ -7,6 +7,7 @@ #include +#include #include #include "components/zucchini/image_utils.h" @@ -21,11 +22,11 @@ class TargetSource; // with a list of associated reference types, only used during patch generation. class TargetPool { public: - using const_iterator = std::vector::const_iterator; + using const_iterator = std::deque::const_iterator; TargetPool(); // Initializes the object with given sorted and unique |targets|. - explicit TargetPool(std::vector&& targets); + explicit TargetPool(std::deque&& targets); TargetPool(TargetPool&&); TargetPool(const TargetPool&); ~TargetPool(); @@ -62,7 +63,7 @@ class TargetPool { void FilterAndProject(const OffsetMapper& offset_mapper); // Accessors for testing. - const std::vector& targets() const { return targets_; } + const std::deque& targets() const { return targets_; } const std::vector& types() const { return types_; } // Returns the number of targets. @@ -72,7 +73,7 @@ class TargetPool { private: std::vector types_; // Enumerates type_tag for this pool. - std::vector targets_; // Targets for pool in ascending order. + std::deque targets_; // Targets for pool in ascending order. }; } // namespace zucchini -- cgit v1.2.3