From ded7a661b7ca4c9adc8d2f998643f3705297daa8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 31 Mar 2026 12:00:07 +0100 Subject: [PATCH] Add fast path --- synapse/util/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py index 51d2fb847f..a2a9bfecc9 100644 --- a/synapse/util/__init__.py +++ b/synapse/util/__init__.py @@ -218,6 +218,13 @@ def split_dict_to_fit_to_size( if not original_dict: return + # Check if the whole dict fits within the size limit. If it does, we can + # skip the splitting logic and just return the original dict. + full_size = _len_with_wrapping_object(original_dict, wrapping_object_size) + if full_size <= soft_max_size: + yield (original_dict, full_size) + return + # The current payload being built up. We keep track of the estimated size of # the JSON encoding of this payload so that we can decide when to start a # new one.