Avoid loading KeyStore/TrustStore over and over again
CryptoConfigurator
contains 3 places where KeyStore.load()
is called. These calls have proven to be quite expensive (~150 ms each).
Currently, loading the KeyStore/TrustStore is done over and over again, even if the CryptoSettings
are always the same. As a result, when connecting to 10 devices, KeyStore.load()
is called 158 times which takes ~30 CPU seconds!
Things get massively worse when connecting to hundreds of devices.
In contrast, when loading from the KeyStore/TrustStore only if CryptoSettings
are unknown, KeyStore.load()
is only called 8 times which takes ~1 second. (no matter how many devices are connected to)
I will provide an example solution in a MR, but I am sure you will find an even better solution.
Update 2022-09-15:
The problem seems to be less severe now. Maybe, loading the Keystore has become much faster in Java 17??
CryptoConfigurator.createSslContextFromCryptoConfig()
now takes ~30..50 ms on my machine, CryptoConfigurator.getCertificates()
~10..15 ms.
Sure, reading the keystore/truststore again and again is still noticeable, but 10x less so.
Update 2022-09-15:
We discussed this issue with our PO again and he decided that we do need a fix for this. We don't want to waste time if connecting to many devices.