作者:指定不告诉你 | 来源:互联网 | 2023-09-11 13:25
Sometimes you want to distinguish between a value not found, and a default value. For example, in Play there are many times when we only want to do something if a value is configured, one good example is when we offer configuration for third party libraries, and we want that library to be responsible for choosing the default value if it's not configured, so we want to know if no value is configured - this means we don't put a value in reference.conf, nor do we pass a default value to the lookup method.
The only mechanism Typesafe config offers to achieve this is throwing an exception. While not ideal, it's workable with Scala. But it's very slow, because creating stack traces is slow. If Typesafe config is going to use exceptions for control flow like that, then it should not fill in the stack trace of those exceptions. This can be done by overriding the
method on the exceptions it throws to do nothing.
This would fix some significant performance problems in Play, as described here.
该提问来源于开源项目:lightbend/config
I made path parsing substantially faster in https://github.com/typesafehub/config/commit/0a7db6a1260b907b68a303f8c2f9f448482776e3
It was pretty easy to avoid a number of object allocations for simple paths (containing just ASCII alpha chars, hyphen, and underscore).
hasPath now runs in about .0001ms which I'm going to declare Good Enough; if Play uses hasPath instead of catching Missing, it should be about 30x faster plus it should be a predictable speed and not dependent on stack size. Also things may now be fast enough that Akka could get rid of that CachingConfig thing. There's some more room for micro-optimization, though I don't know how much. To make more progress it's probably important to set up sbt-jmh so the benchmarking isn't so crude.