This PR add a cache to avoid to call process.env each time (which can create performance issue).
One thing we need to consider is that those values should be only accessed in the config file of the framework (and then cached there). So this change is only relevant for the start-up time of an AdonisJS application.
We should probably do few benchmarks to know if accessing process.env (only 3 times) is slower than creating a Map and using .has() and .get().
From the tests of this repository, we went from ~18ms to ~30ms with those changes.
In my opinion, we should cache process.env values only in core's module like we did here.
Env.get() shouldn't be called in the application code, therefore, this cache may make the code slower than no cache.
Hey 👋 !
This PR add a cache to avoid to call
process.env
each time (which can create performance issue).One thing we need to consider is that those values should be only accessed in the config file of the framework (and then cached there). So this change is only relevant for the start-up time of an AdonisJS application.
We should probably do few benchmarks to know if accessing
process.env
(only 3 times) is slower than creating aMap
and using.has()
and.get()
.From the tests of this repository, we went from
~18ms
to~30ms
with those changes.In my opinion, we should cache
process.env
values only in core's module like we did here.Env.get()
shouldn't be called in the application code, therefore, this cache may make the code slower than no cache.