ivi icon indicating copy to clipboard operation
ivi copied to clipboard

Performance issues related to using environment variables

Open katyo opened this issue 5 years ago • 2 comments

As I see, you access to process.env many-many times as here:

export const EVENT_DISPATCHER_ABORT = (
  process.env.IVI_TARGET === "ssr" ? void 0 :
  /*#__PURE__*/createNativeEventDispatcher<UIEvent>(NativeEventSourceFlags.Capture, "abort")
);
export const EVENT_DISPATCHER_ACTIVATE = (
  process.env.IVI_TARGET === "ssr" ? void 0 :
  /*#__PURE__*/createNativeEventDispatcher<UIEvent>(NativeEventSourceFlags.Capture | NativeEventSourceFlags.Bubbles, "activate")
);
// ...

It's not an issue for pre-compiled/pre-bundled client apps. But it can slowdown server-side startup and/or rendering because process.env is not transparent object. I suggest assing values of process.env.NODE_ENV and process.env.IVI_TARGET to internal constants IVI_ENV and IVI_TARGET respectively. It's harmless because JS optimizers can deal with it.

See: https://github.com/facebook/fbjs/pull/86#issuecomment-285204734 https://github.com/facebook/react/issues/812

katyo avatar Mar 22 '19 05:03 katyo

It's not an issue for pre-compiled/pre-bundled client apps.

Just tried it with the latest webpack+terser, and it is still unable to deal with it and leaves alot of unused functions. Rollup+terser can deal with it.

Maybe precompile commonjs package entry for SSR and production?

localvoid avatar Mar 22 '19 09:03 localvoid

Hmm... It seems webpack prevent optimizing constants from imported modules.

katyo avatar Mar 22 '19 12:03 katyo