browserify / node-util

node.js util module as a module
MIT License
247 stars 88 forks source link

object.entries is 1MB of javascript #45

Closed Raynos closed 4 years ago

Raynos commented 4 years ago

1MB of javascript is imported to avoid writing a for loop :(

ljharb commented 4 years ago

Where are you getting that measurement?

(Also Object.entries is much more difficult to get right than just writing a for loop)

Raynos commented 4 years ago

I get the measurement here

https://packagephobia.now.sh/result?p=object.entries@1.1.0

I was originally looking at https://packagephobia.now.sh/result?p=util and https://packagephobia.now.sh/result?p=assert

I was trying to identify the regression that caused the size increase and it was object.entries

Here is another library with a different measurement

$ howfat util -r tree
util@0.12.1 (21 deps, 1.29mb, 946 files)
├── inherits@2.0.4 (3.87kb, 5 files)
├── is-arguments@1.0.4 (19.29kb, 10 files)
├── is-generator-function@1.0.7 (23.59kb, 15 files)
├─┬ object.entries@1.1.1 (16 deps, 1.18mb, 903 files)
│ ├─┬ define-properties@1.1.3 (1 dep, 48.41kb, 21 files)
│ │ ╰── object-keys@1.1.1 (25.92kb, 11 files)
│ ├─┬ es-abstract@1.17.4 (15 deps, 1.16mb, 887 files)
│ │ ├─┬ es-to-primitive@1.2.1 (4 deps, 113.37kb, 68 files)
│ │ │ ├── is-callable@1.1.5 (🔗, 17.16kb, 13 files)
│ │ │ ├── is-date-object@1.0.2 (19.97kb, 11 files)
│ │ │ ╰─┬ is-symbol@1.0.3 (1 dep, 36.76kb, 27 files)
│ │ │   ╰── has-symbols@1.0.1 (🔗, 15.11kb, 14 files)
│ │ ├── function-bind@1.1.1 (🔗, 24.56kb, 12 files)
│ │ ├── has@1.0.3 (🔗, 1 dep, 27.27kb, 17 files)
│ │ ├── has-symbols@1.0.1 (15.11kb, 14 files)
│ │ ├── is-callable@1.1.5 (17.16kb, 13 files)
│ │ ├─┬ is-regex@1.0.5 (2 deps, 50.1kb, 26 files)
│ │ │ ╰── has@1.0.3 (🔗, 1 dep, 27.27kb, 17 files)
│ │ ├── object-inspect@1.7.0 (29.93kb, 29 files)
│ │ ├── object-keys@1.1.1 (25.92kb, 11 files)
│ │ ├─┬ object.assign@4.1.0 (4 deps, 133.35kb, 66 files)
│ │ │ ├── define-properties@1.1.3 (🔗, 1 dep, 48.41kb, 21 files)
│ │ │ ├── function-bind@1.1.1 (🔗, 24.56kb, 12 files)
│ │ │ ├── has-symbols@1.0.1 (🔗, 15.11kb, 14 files)
│ │ │ ╰── object-keys@1.1.1 (🔗, 25.92kb, 11 files)
│ │ ├─┬ string.prototype.trimleft@2.1.1 (3 deps, 84.17kb, 48 files)
│ │ │ ├── define-properties@1.1.3 (🔗, 1 dep, 48.41kb, 21 files)
│ │ │ ╰── function-bind@1.1.1 (🔗, 24.56kb, 12 files)
│ │ ╰─┬ string.prototype.trimright@2.1.1 (3 deps, 84.2kb, 48 files)
│ │   ├── define-properties@1.1.3 (🔗, 1 dep, 48.41kb, 21 files)
│ │   ╰── function-bind@1.1.1 (🔗, 24.56kb, 12 files)
│ ├── function-bind@1.1.1 (24.56kb, 12 files)
│ ╰─┬ has@1.0.3 (1 dep, 27.27kb, 17 files)
│   ╰── function-bind@1.1.1 (🔗, 24.56kb, 12 files)
╰── safe-buffer@5.2.0 (31.18kb, 5 files)
Raynos commented 4 years ago

As a more useful suggestion; it looks like object.entries is only used in tests and should be a devDependency.

ljharb commented 4 years ago

That site has grossly inaccurate measurements ftr, by virtue of not accounting for app-level bundle/npm deduping and optimizations.

vweevers commented 4 years ago

Also don't need full spec compliance here, could use a simpler & smaller ~polyfill~ whatever.

goto-bus-stop commented 4 years ago

yeah, packagephobia measures the installed size, which is important to some people. i wouldn't choose a package based on that alone though…maybe if there is 100s of megs of difference :)

moved it to a devDependency in :package: 0.12.2. thanks for the report!

Raynos commented 4 years ago

Thanks that's awesome.

ljharb commented 4 years ago

@vweevers its not a polyfill unless it has full spec compliance; certainly if you don’t need the spec method you could use something simpler.

Glad to see the dep category fixed :-)