This is an automated email from the ASF dual-hosted git repository. timothyjward pushed a commit to branch maint/1.0.x in repository https://gitbox.apache.org/repos/asf/aries-typedevent.git
commit cceb0d877426456dd0a4ed04189369352c49548c Author: Tim Ward <timothyjw...@apache.org> AuthorDate: Thu May 1 10:09:23 2025 +0100 BACKPORT - Improve conversion performance for Record to Map This is a common transformation as all events are converted to Maps for monitoring. Records will typically have a small number of components and we can reduce the overhead of each Map by setting the capacity and load factor properly. Signed-off-by: Tim Ward <timothyjw...@apache.org> --- .../java16/org/apache/aries/typedevent/bus/impl/RecordConverter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/org.apache.aries.typedevent.bus/src/main/java16/org/apache/aries/typedevent/bus/impl/RecordConverter.java b/org.apache.aries.typedevent.bus/src/main/java16/org/apache/aries/typedevent/bus/impl/RecordConverter.java index fd7756f..4eadc0d 100644 --- a/org.apache.aries.typedevent.bus/src/main/java16/org/apache/aries/typedevent/bus/impl/RecordConverter.java +++ b/org.apache.aries.typedevent.bus/src/main/java16/org/apache/aries/typedevent/bus/impl/RecordConverter.java @@ -61,7 +61,8 @@ public class RecordConverter { } return createRecord(clz, args, argTypes); } else { - Map<String, Object> converted = new HashMap<>(sourceComponents.length); + // Avoid rehashing on insertion and reduce the iteration overhead of empty buckets + Map<String, Object> converted = new HashMap<>((int) (sourceComponents.length / 0.9f + 1.0f), 0.9f); for(RecordComponent rc : sourceComponents) { converted.put(rc.getName(), getComponentValue(rc, o)); }