performance - What is the cost of access to a configuration property? -



performance - What is the cost of access to a configuration property? -

i'm developing scala app scan folders in interval of 10 minutes. within class, i've created 12 global variable , it's kinda unusual because variables used 1 time on exception point.

i wondering cost of use:

configuration.getstring("value")

every time instead create global variable like:

private lazy val inputpath = configuration.getstring("main.directory")

in terms of performance, better? phone call when it's necessary or create lazy global variable?

thank in advance.

configuration.getstring("value") cheap. config read , parsed 1 time @ startup , values stored in java map. calling getstring boils downwards lookup in hashmap. of course of study more expensive shared variable still of constant complexity o(1). should fine when phone call getstring couple of times every 10 minutes.

the implementation im referring can found in sources of typesafe/config on github. line 30 map in values stored.

update: question came mind morning , struck me why bad thought after phone call getstring instead of initializing shared variable value. didn't come mind because has nil performance:

getstring has side effects namely can throw exception when config value not nowadays - config file might corrupted instance. since there no recovery strategy kind of exception, much improve practice have these potential failures @ startup instead of couple of tens of minutes programme when nobody watching anymore.

in question used lazy val alternative exposed same problem, since evaluated when needed. in sentiment should read config values vals @ origin of program!

private val inputpath = configuration.getstring("main.directory")

this of course of study not apply if utilize fallback values , 100% positive there no exceptions.

performance scala playframework

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -