This is an automated email from the ASF dual-hosted git repository.

timothyjward pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/aries-typedevent.git


The following commit(s) were added to refs/heads/main by this push:
     new ab12e75  Improve conversion performance for Record to Map
ab12e75 is described below

commit ab12e758bde6428bd494bd5aa01e8ed03fd46824
Author: Tim Ward <timothyjw...@apache.org>
AuthorDate: Thu May 1 10:09:23 2025 +0100

    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 af779d3..3e27639 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));
                        }

Reply via email to