From 0e32c0a7bc4e806955c065467b732b985408e7ca Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 14 Sep 2017 16:03:57 -0700 Subject: [PATCH] Fix speed regression in property binding Update `MapBinder` to only compute values if an entry does not already exist. Prior to this commit, a binding to `Map>` would be expensive since the same entries would be bound many times. For example, given: foo.bar[0]=baz1 foo.bar[1]=baz1 foo.bar[2]=baz1 The Map binder would iterate over the properties `bar[0]`, `bar[1]` and `bar[2]`. Each of these properties resulted in the same actual key of `bar` which would then be bound to list multiple times. Fixes gh-10093 --- .../boot/context/properties/bind/MapBinder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java b/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java index abb657a2e79..42bc614637b 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/MapBinder.java @@ -103,8 +103,8 @@ class MapBinder extends AggregateBinder> { ConfigurationPropertyName entryName = getEntryName(source, name); Object key = getContext().getConversionService() .convert(getKeyName(entryName), this.keyType); - Object value = this.elementBinder.bind(entryName, valueBindable); - map.putIfAbsent(key, value); + map.computeIfAbsent(key, + (k) -> this.elementBinder.bind(entryName, valueBindable)); } } }