0

I received an interesting code review comment and I wanted to know how import types in components, hooks, etc. affect performance.

The question is whether there is a performance difference between the two examples below and why?

1. import _ from 'lodash'; // then, use _.isEmpty;
2. import { isEmpty } from 'lodash/isEmpty';

My understanding was that the import is a reference of that function that gets bundled the same in the end - but I don't know too much about it.

Perhaps, another possible context to consider - may be local hot-reloading.

Edv Beq
  • 910
  • 3
  • 18
  • 43
  • 1
    The second should be `import isEmpty from 'lodash/isEmpty';` and yes, there is a difference since it will only import `isEmpty`, not the whole bundle of Lodash of which you'd use only one item. That's not down to "performance" as it's not CPU cycles that you save but memory. – VLAZ May 19 '23 at 20:41

0 Answers0