adonisjs / env

Framework agnostic environment variables parser and validator
https://docs.adonisjs.com/guides/environment-variables
MIT License
35 stars 10 forks source link

feat: cache value of process.env #12

Closed RomainLanz closed 4 years ago

RomainLanz commented 4 years ago

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 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.