Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache access to process.env #8680

Open
jnields opened this issue Aug 20, 2018 · 0 comments
Open

Cache access to process.env #8680

jnields opened this issue Aug 20, 2018 · 0 comments

Comments

@jnields
Copy link

jnields commented Aug 20, 2018

What problem does this feature solve?

Access to process.env is a slow, system-bound call.

After react restructured their project to cache access to process.env, they had a 2.4x - 3.8x performance improvement for server-side rendering,

facebook/react#812

This should also be done for vue, vue-server-renderer, vuex ... anything that accesses process.env.

What does the proposed API look like?

An easy strategy might be to replace references to process.env.NODE_ENV with a reference to a singleton that checks process.env.NODE_ENV.

// foo.js
if (process.env.NODE_ENV !== 'production') {
  // do stuff
}

becomes

// isDevEnv.js
export default process.env.NODE_ENV !== 'production';

// foo.js
import isDevEnv from './isDevEnv';

if (isDevEnv) {
  // do stuff
}
@jnields jnields changed the title Cache access to process.env.NODE_ENV Cache access to process.env.NODE_ENV Aug 20, 2018
@jnields jnields changed the title Cache access to process.env.NODE_ENV Cache access to process.env Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants