-
Notifications
You must be signed in to change notification settings - Fork 41.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve configuration property binding performance with extremely large input files #16401
Comments
I want to investigate on this issue.can i do? |
I'm currently working already on some improvements as well, @wilkinsona . See the referenced issue #16447 for one of those. I'm currently working on another one already, but I'm not confident enough in the solution yet. |
Other than the already provided PRs I'm still trying around on this and found one interesting place that you might want to look at. When simply assigning the cache key in
Unfortunately, this is meant to fix #13344 and can thus not be removed at the moment. For the given example this means that AbstractSet.equals() is called on Sets with 5000 entries basically every time someone interacts with I'm currently not able to try out things a lot, but I wanted to let you know at least. Maybe there is a way to change the CacheKey creation. Maybe there is a way to create something like an Cheers, |
Ouch, that's a heavy price to pay for something that's only of benefit to a subset of users. Thanks for identifying it. I wonder if we can use an diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java
index 241ce2180b..50d3680336 100644
--- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java
+++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/SpringIterableConfigurationPropertySource.java
@@ -44,7 +44,7 @@ import org.springframework.util.ObjectUtils;
class SpringIterableConfigurationPropertySource extends SpringConfigurationPropertySource
implements IterableConfigurationPropertySource {
- private volatile Object cacheKey;
+ private volatile CacheKey cacheKey;
private volatile Cache cache;
@@ -131,7 +131,7 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
}
private Cache getCache() {
- CacheKey cacheKey = CacheKey.get(getPropertySource());
+ CacheKey cacheKey = CacheKey.get(this.cacheKey, getPropertySource());
if (ObjectUtils.nullSafeEquals(cacheKey, this.cacheKey)) {
return this.cache;
}
@@ -204,9 +204,14 @@ class SpringIterableConfigurationPropertySource extends SpringConfigurationPrope
return this.key.hashCode();
}
- public static CacheKey get(EnumerablePropertySource<?> source) {
+ public static CacheKey get(CacheKey existingCacheKey,
+ EnumerablePropertySource<?> source) {
if (source instanceof MapPropertySource) {
- return new CacheKey(((MapPropertySource) source).getSource().keySet());
+ Object key = ((MapPropertySource) source).getSource().keySet();
+ if (existingCacheKey != null && existingCacheKey.key == key) {
+ return existingCacheKey;
+ }
+ return new CacheKey(key);
}
return new CacheKey(source.getPropertyNames());
} |
@dreis2211 What's the
|
Interesting - I tested with quite a few baselines. Basically I switch to a new one after one of my provided PRs was merged to master. So the current baseline is a 2.2.0 snapshot, but even with M2 I get very different results to yours.
Just for completeness - I added a To your suggestion. That shouldn't make a difference as we're still comparing a LinkedKeySet vs. a HashSet where |
@wilkinsona If I interpret your benchmark correctly, you're comparing a M2 as baseline vs. a current snapshot plus your diff, right? As noted I don't think your patch should make a difference, but maybe you're seeing the improvements of my previous PRs (although with a smaller impact than on my machine). So maybe your machine is simply a lot faster than mine!? I'm running on a Windows machine with an Intel Core (i7) 4xCore @2.40Ghz and 8GB of RAM and Java 1.8.0_201 at the moment. Maybe you're already running on a higher JDK version (Compact Strings and String Concat optimizations come to my mind here)? |
@wilkinsona Any chance you had time to look into my questions? :) |
Update `SpringIterableConfigurationPropertySource` so that cache keys do not need to be checked if property sources are immutable. See gh-16401
Make immutable properties more explicit and trust that they truly won't change. See gh-16401
* pr/16717: Polish "Optimize CacheKey handling for immutable sources" Optimize CacheKey handling for immutable sources Closes gh-16401
Courtesy of @martinvisser, we have an example of the binder still being slow in 2.2 snapshots relative to 1.5's performance. The input YAML file is 7500 lines long so considerably bigger than the case we investigated with Initializr.
The text was updated successfully, but these errors were encountered: