Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@vladimirkl
Copy link
Contributor

@vladimirkl vladimirkl commented Jun 7, 2023

Hi, I noticed that ConfigProvider.fromMap using indexed data performs badly on large map (close to 1000 keys). In my case it's coming from huge Typesafe config file. This happens because of enumerateChildren implementation that loops over whole map every time it is called. To avoid this I used TreeSet to cache keys and use O(log n) search for enumeration. I've also provided benchmark, here are results:

Before optimisation
[info] Benchmark                                  (keyCount)   Mode  Cnt       Score      Error  Units
[info] ConfigProviderBenchmark.loadFlatConfig             10  thrpt   10  132029.533 ± 1118.191  ops/s
[info] ConfigProviderBenchmark.loadFlatConfig           1000  thrpt   10    1139.194 ±   14.454  ops/s
[info] ConfigProviderBenchmark.loadIndexedConfig          10  thrpt   10    2244.199 ±   12.644  ops/s
[info] ConfigProviderBenchmark.loadIndexedConfig        1000  thrpt   10       0.432 ±    0.008  ops/s

After optimisation
[info] Benchmark                                  (keyCount)   Mode  Cnt       Score      Error  Units
[info] ConfigProviderBenchmark.loadFlatConfig             10  thrpt   10  131404.586 ± 1809.497  ops/s
[info] ConfigProviderBenchmark.loadFlatConfig           1000  thrpt   10    1146.160 ±    8.240  ops/s
[info] ConfigProviderBenchmark.loadIndexedConfig          10  thrpt   10    4606.698 ±   46.079  ops/s
[info] ConfigProviderBenchmark.loadIndexedConfig        1000  thrpt   10      35.104 ±    0.466  ops/s

So loadIndexedConfig benchmark on 1000 keys performs approximately 80 times faster after my change. Please note that I didn't change fromEnv and fromProps - because we cannot cache keys easily there and I doubt that these providers are ever used for large number of keys.

@vladimirkl vladimirkl force-pushed the bugfix/config-provider-performance branch from 7163fac to dedea25 Compare June 7, 2023 20:21
@adamgfraser adamgfraser merged commit 8431d6f into zio:series/2.x Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants