ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.44k stars 1.25k forks source link

Reduce Dexie.js's minified size #745

Closed haadcode closed 7 years ago

haadcode commented 7 years ago

Noticed that when I'm bundling (orbit-db with js-ipfs) with webpack, Dexie.js is at 199kb (in the minified build) but dexie's official minified build is 53kb.

We should check if we can reduce its sie to similar level as the official minified build. This would reduce the disk footprint of js-ipfs build.

 [152] ./~/dexie/dist/dexie.js 199 kB {0} [built]
haadcode commented 7 years ago

Just had a conversation on IRC with @dignifiedquire:

04:07 <@dignifiedquire> haad: webpack numbers in the log are usually nonminified
04:07 <+haad> dignifiedquire: even with after uglifying? :O
04:07 <@dignifiedquire> yes

So it may be that the numbers here are incorrect.

Will investigate, mark this issue as invalid for now, but don't close until we've verified that that's the case.

haadcode commented 7 years ago

Looking into the number as per ^, ran a quick test with ipfs-log:

samuli:~/code/ipfs-log$ npm run build:dist

> ipfs-log@2.0.0-beta.1 build:dist /Users/samuli/code/ipfs-log
> webpack --config webpack.config.js --display-modules --sort-modules-by size

Hash: 584b0579324f531c6f91
Version: webpack 2.2.0
Time: 243ms
                Asset     Size  Chunks             Chunk Names
./dist/ipfslog.min.js  73.5 kB       0  [emitted]  main
   [4] ./~/isarray/index.js 132 bytes {0} [built]
   [2] ./src/map-series.js 371 bytes {0} [built]
   [6] (webpack)/buildin/global.js 509 bytes {0} [built]
   [3] ./~/ieee754/index.js 2.05 kB {0} [built]
   [1] ./src/entry.js 3.08 kB {0} [built]
   [5] ./~/node-libs-browser/~/base64-js/index.js 3.48 kB {0} [built]
   [7] ./src/log.js 11.9 kB {0} [built]
   [0] ./~/node-libs-browser/~/buffer/index.js 48.6 kB {0} [built]
samuli:~/code/ipfs-log$ npm run build:dist

> ipfs-log@2.0.0-beta.1 build:dist /Users/samuli/code/ipfs-log
> webpack --config webpack.config.js --display-modules --sort-modules-by size

Hash: b0f89657d86ca0494cdc
Version: webpack 2.2.0
Time: 126ms
                Asset   Size  Chunks             Chunk Names
./dist/ipfslog.min.js  18 kB       0  [emitted]  main
   [1] ./src/map-series.js 371 bytes {0} [built]
   [0] ./src/entry.js 3.08 kB {0} [built]
   [2] ./src/log.js 11.9 kB {0} [built]

The first is the normal minified build. The second is without Buffer included in the code.

Normal: 73.50kb no-Buffer: reduction of 54.53kb

To me that looks like the numbers are minified sizes. Am I missing something @dignifiedquire?

dignifiedquire commented 7 years ago

hmm looks like the second numbers are minified, interesting. Could you post the full log from the build with dexie please?

haadcode commented 7 years ago

Sure. This is the full output from building minified orbit-db:

> orbit-db@0.16.3 build:minified /Users/samuli/code/orbit-db
> webpack --config conf/webpack.config.minified.js --display-modules --sort-modules-by size

Hash: 05ae1ac36fabcf9f5a1d
Version: webpack 2.2.1
Time: 5553ms
                Asset    Size  Chunks                    Chunk Names
./dist/orbitdb.min.js  253 kB       0  [emitted]  [big]  main
  [72] ./~/core-js/library/modules/es6.object.to-string.js 0 bytes {0} [built]
  [23] ./~/core-js/library/modules/_iterators.js 20 bytes {0} [built]
  [28] ./~/core-js/library/modules/_library.js 22 bytes {0} [built]
  [50] ./~/core-js/library/modules/_wks-ext.js 30 bytes {0} [built]
  [69] ./~/core-js/library/modules/_redefine.js 36 bytes {0} [built]
  [29] ./~/core-js/library/modules/_object-pie.js 36 bytes {0} [built]
 [151] ./~/core-js/library/modules/es7.symbol.observable.js 39 bytes {0} [built]
  [43] ./~/core-js/library/modules/_object-gops.js 41 bytes {0} [built]
 [150] ./~/core-js/library/modules/es7.symbol.async-iterator.js 42 bytes {0} [built]
 [116] ./~/core-js/library/modules/_add-to-unscopables.js 43 bytes {0} [built]
  [86] ./~/orbit-db-pubsub/index.js 61 bytes {0} [built]
  [60] ./~/core-js/library/modules/_html.js 75 bytes {0} [built]
 [127] ./~/core-js/library/modules/_iter-step.js 81 bytes {0} [built]
 [102] ./~/babel-runtime/core-js/symbol.js 87 bytes {0} [built]
  [27] ./~/babel-runtime/core-js/promise.js 88 bytes {0} [built]
  [13] ./~/babel-runtime/core-js/object/keys.js 92 bytes {0} [built]
  [99] ./~/babel-runtime/core-js/object/create.js 94 bytes {0} [built]
   [9] ./~/babel-runtime/core-js/object/assign.js 94 bytes {0} [built]
  [37] ./~/babel-runtime/core-js/json/stringify.js 95 bytes {0} [built]
  [57] ./~/babel-runtime/core-js/symbol/iterator.js 96 bytes {0} [built]
  [17] ./~/core-js/library/modules/_fails.js 99 bytes {0} [built]
 [111] ./~/core-js/library/fn/object/keys.js 102 bytes {0} [built]
  [56] ./~/babel-runtime/core-js/object/define-property.js 103 bytes {0} [built]
  [21] ./~/core-js/library/modules/_cof.js 103 bytes {0} [built]
  [14] ./~/babel-runtime/core-js/object/get-prototype-of.js 104 bytes {0} [built]
 [101] ./~/babel-runtime/core-js/object/set-prototype-of.js 104 bytes {0} [built]
 [106] ./~/core-js/library/fn/object/assign.js 106 bytes {0} [built]
  [18] ./~/core-js/library/modules/_is-object.js 107 bytes {0} [built]
 [100] ./~/babel-runtime/core-js/object/get-own-property-names.js 110 bytes {0} [built]
 [169] ./~/pull-stream/sinks/on-end.js 116 bytes {0} [built]
   [2] ./~/core-js/library/modules/_core.js 117 bytes {0} [built]
  [10] ./~/core-js/library/modules/_has.js 117 bytes {0} [built]
  [38] ./~/core-js/library/modules/_a-function.js 120 bytes {0} [built]
 [112] ./~/core-js/library/fn/object/set-prototype-of.js 124 bytes {0} [built]
 [175] ./~/pull-stream/sources/keys.js 124 bytes {0} [built]
 [110] ./~/core-js/library/fn/object/get-prototype-of.js 124 bytes {0} [built]
  [32] ./~/core-js/library/modules/_to-object.js 129 bytes {0} [built]
  [78] ./~/pull-stream/util/abort-cb.js 131 bytes {0} [built]
 [157] ./~/isarray/index.js 132 bytes {0} [built]
 [171] ./~/pull-stream/sources/empty.js 135 bytes {0} [built]
 [172] ./~/pull-stream/sources/error.js 140 bytes {0} [built]
 [123] ./~/core-js/library/modules/_is-array.js 145 bytes {0} [built]
 [144] ./~/core-js/library/modules/es6.object.get-own-property-names.js 147 bytes {0} [built]
   [5] ./~/core-js/library/modules/_an-object.js 149 bytes {0} [built]
 [168] ./~/pull-stream/sinks/log.js 153 bytes {0} [built]
 [165] ./~/pull-stream/sinks/concat.js 154 bytes {0} [built]
 [115] ./~/core-js/library/fn/symbol/iterator.js 154 bytes {0} [built]
  [39] ./~/core-js/library/modules/_defined.js 157 bytes {0} [built]
 [147] ./~/core-js/library/modules/es6.object.set-prototype-of.js 157 bytes {0} [built]
  [33] ./~/core-js/library/modules/_uid.js 158 bytes {0} [built]
  [45] ./~/core-js/library/modules/_shared-key.js 158 bytes {0} [built]
 [142] ./~/core-js/library/modules/es6.object.create.js 158 bytes {0} [built]
  [47] ./~/core-js/library/modules/_to-integer.js 158 bytes {0} [built]
 [141] ./~/core-js/library/modules/es6.object.assign.js 159 bytes {0} [built]
  [41] ./~/core-js/library/modules/_enum-bug-keys.js 159 bytes {0} [built]
 [107] ./~/core-js/library/fn/object/create.js 170 bytes {0} [built]
   [6] ./~/core-js/library/modules/_descriptors.js 177 bytes {0} [built]
 [164] ./~/pull-stream/sinks/collect.js 177 bytes {0} [built]
  [30] ./~/core-js/library/modules/_property-desc.js 183 bytes {0} [built]
 [181] ./~/pull-stream/throughs/non-unique.js 187 bytes {0} [built]
  [61] ./~/core-js/library/modules/_ie8-dom-define.js 192 bytes {0} [built]
  [46] ./~/core-js/library/modules/_shared.js 198 bytes {0} [built]
 [174] ./~/pull-stream/sources/infinite.js 201 bytes {0} [built]
 [188] ./~/util/support/isBufferBrowser.js 203 bytes {0} [built]
   [0] ./~/babel-runtime/helpers/classCallCheck.js 208 bytes {0} [built]
 [109] ./~/core-js/library/fn/object/get-own-property-names.js 208 bytes {0} [built]
 [133] ./~/core-js/library/modules/_redefine-all.js 210 bytes {0} [built]
 [177] ./~/pull-stream/throughs/filter-not.js 212 bytes {0} [built]
  [12] ./~/core-js/library/modules/_to-iobject.js 213 bytes {0} [built]
 [108] ./~/core-js/library/fn/object/define-property.js 213 bytes {0} [built]
 [143] ./~/core-js/library/modules/es6.object.define-property.js 214 bytes {0} [built]
 [113] ./~/core-js/library/fn/promise.js 215 bytes {0} [built]
 [170] ./~/pull-stream/sources/count.js 216 bytes {0} [built]
  [71] ./~/core-js/library/modules/_to-length.js 217 bytes {0} [built]
 [146] ./~/core-js/library/modules/es6.object.keys.js 223 bytes {0} [built]
  [19] ./~/core-js/library/modules/_object-keys.js 225 bytes {0} [built]
 [138] ./~/core-js/library/modules/_to-index.js 230 bytes {0} [built]
 [117] ./~/core-js/library/modules/_an-instance.js 232 bytes {0} [built]
  [62] ./~/core-js/library/modules/_iobject.js 236 bytes {0} [built]
 [114] ./~/core-js/library/fn/symbol/index.js 239 bytes {0} [built]
 [173] ./~/pull-stream/sources/index.js 240 bytes {0} [built]
 [167] ./~/pull-stream/sinks/index.js 241 bytes {0} [built]
 [105] ./~/core-js/library/fn/json/stringify.js 242 bytes {0} [built]
  [31] ./~/core-js/library/modules/_set-to-string-tag.js 253 bytes {0} [built]
  [79] ./~/pull-stream/util/tester.js 265 bytes {0} [built]
 [145] ./~/core-js/library/modules/es6.object.get-prototype-of.js 275 bytes {0} [built]
 [122] ./~/core-js/library/modules/_is-array-iter.js 277 bytes {0} [built]
  [25] ./~/pull-stream/util/prop.js 283 bytes {0} [built]
  [40] ./~/core-js/library/modules/_dom-create.js 286 bytes {0} [built]
  [11] ./~/core-js/library/modules/_hide.js 288 bytes {0} [built]
  [66] ./~/core-js/library/modules/_object-gopn.js 290 bytes {0} [built]
 [139] ./~/core-js/library/modules/core.get-iterator-method.js 293 bytes {0} [built]
 [128] ./~/core-js/library/modules/_keyof.js 307 bytes {0} [built]
  [76] ./~/pull-stream/sources/once.js 313 bytes {0} [built]
  [75] ./~/pull-stream/index.js 313 bytes {0} [built]
   [4] ./~/core-js/library/modules/_global.js 322 bytes {0} [built]
 [179] ./~/pull-stream/throughs/index.js 329 bytes {0} [built]
 [136] ./~/core-js/library/modules/_species-constructor.js 340 bytes {0} [built]
  [44] ./~/core-js/library/modules/_object-sap.js 368 bytes {0} [built]
   [3] ./~/core-js/library/modules/_wks.js 368 bytes {0} [built]
 [159] ./~/looper/index.js 391 bytes {0} [built]
 [124] ./~/core-js/library/modules/_iter-call.js 403 bytes {0} [built]
 [132] ./~/core-js/library/modules/_object-dps.js 404 bytes {0} [built]
 [161] ./~/pull-defer/sink.js 419 bytes {0} [built]
  [77] ./~/pull-stream/throughs/unique.js 428 bytes {0} [built]
  [49] ./~/core-js/library/modules/_wks-define.js 439 bytes {0} [built]
 [135] ./~/core-js/library/modules/_set-species.js 449 bytes {0} [built]
 [119] ./~/core-js/library/modules/_enum-keys.js 472 bytes {0} [built]
 [183] ./~/pull-stream/throughs/through.js 473 bytes {0} [built]
 [166] ./~/pull-stream/sinks/find.js 478 bytes {0} [built]
 [180] ./~/pull-stream/throughs/map.js 484 bytes {0} [built]
  [53] ./~/pull-stream/throughs/filter.js 488 bytes {0} [built]
  [67] ./~/core-js/library/modules/_object-gpo.js 497 bytes {0} [built]
  [22] ./~/core-js/library/modules/_ctx.js 505 bytes {0} [built]
  [35] (webpack)/buildin/global.js 509 bytes {0} [built]
  [51] ./~/pull-stream/sinks/reduce.js 521 bytes {0} [built]
  [73] ./~/core-js/library/modules/es6.string.iterator.js 523 bytes {0} [built]
  [52] ./~/pull-stream/sources/values.js 523 bytes {0} [built]
 [125] ./~/core-js/library/modules/_iter-create.js 528 bytes {0} [built]
 [103] ./~/babel-runtime/helpers/defineProperty.js 540 bytes {0} [built]
  [16] ./~/babel-runtime/helpers/possibleConstructorReturn.js 542 bytes {0} [built]
  [68] ./~/core-js/library/modules/_object-keys-internal.js 546 bytes {0} [built]
  [74] ./~/core-js/library/modules/web.dom.iterable.js 559 bytes {0} [built]
 [126] ./~/core-js/library/modules/_iter-detect.js 582 bytes {0} [built]
  [65] ./~/core-js/library/modules/_object-gopn-ext.js 603 bytes {0} [built]
  [64] ./~/core-js/library/modules/_object-gopd.js 607 bytes {0} [built]
   [8] ./~/core-js/library/modules/_object-dp.js 608 bytes {0} [built]
 [137] ./~/core-js/library/modules/_string-at.js 611 bytes {0} [built]
  [91] ./~/ipfs-log/src/map-series.js 612 bytes {0} [built]
  [88] ./~/crdts/src/utils.js 613 bytes {0} [built]
  [48] ./~/core-js/library/modules/_to-primitive.js 644 bytes {0} [built]
 [155] ./~/inherits/inherits_browser.js 672 bytes {0} [built]
  [59] ./~/core-js/library/modules/_classof.js 709 bytes {0} [built]
 [121] ./~/core-js/library/modules/_invoke.js 709 bytes {0} [built]
  [34] ./~/node-libs-browser/mock/process.js 719 bytes {0} [built]
 [187] ./~/typedarray-to-buffer/index.js 786 bytes {0} [built]
 [118] ./~/core-js/library/modules/_array-includes.js 788 bytes {0} [built]
 [134] ./~/core-js/library/modules/_set-proto.js 893 bytes {0} [built]
   [1] ./~/babel-runtime/helpers/createClass.js 904 bytes {0} [built]
 [182] ./~/pull-stream/throughs/take.js 981 bytes {0} [built]
 [156] ./~/is-typedarray/index.js 1.02 kB {0} [built]
 [176] ./~/pull-stream/throughs/async-map.js 1.02 kB {0} [built]
  [58] ./~/babel-runtime/helpers/typeof.js 1.07 kB {0} [built]
  [15] ./~/babel-runtime/helpers/inherits.js 1.11 kB {0} [built]
 [140] ./~/core-js/library/modules/es6.array.iterator.js 1.13 kB {0} [built]
 [131] ./~/core-js/library/modules/_object-assign.js 1.16 kB {0} [built]
 [120] ./~/core-js/library/modules/_for-of.js 1.19 kB {0} [built]
  [93] ./~/orbit-db-counterstore/src/CounterIndex.js 1.2 kB {0} [built]
  [24] ./~/pull-stream/sinks/drain.js 1.23 kB {0} [built]
 [163] ./~/pull-stream/pull.js 1.25 kB {0} [built]
  [96] ./~/orbit-db-kvstore/src/KeyValueIndex.js 1.26 kB {0} [built]
  [94] ./~/orbit-db-docstore/src/DocumentIndex.js 1.26 kB {0} [built]
 [178] ./~/pull-stream/throughs/flatten.js 1.27 kB {0} [built]
  [55] ./~/orbit-db-eventstore/src/EventIndex.js 1.29 kB {0} [built]
  [80] ./~/timers-browserify/main.js 1.36 kB {0} [built]
  [42] ./~/core-js/library/modules/_object-create.js 1.52 kB {0} [built]
 [129] ./~/core-js/library/modules/_meta.js 1.55 kB {0} [built]
 [162] ./~/pull-pushable/index.js 1.64 kB {0} [built]
 [158] ./~/lock/index.js 1.7 kB {0} [built]
 [130] ./~/core-js/library/modules/_microtask.js 1.75 kB {0} [built]
  [95] ./~/orbit-db-feedstore/src/FeedIndex.js 1.8 kB {0} [built]
  [84] ./~/orbit-db-feedstore/src/FeedStore.js 1.87 kB {0} [built]
 [184] ./~/pull-window/index.js 2.04 kB {0} [built]
  [87] ./~/crdts/src/G-Counter.js 2.04 kB {0} [built]
 [154] ./~/ieee754/index.js 2.05 kB {0} [built]
 [185] ./~/pull-write/index.js 2.07 kB {0} [built]
  [98] ./~/orbit-db-store/src/Index.js 2.09 kB {0} [built]
  [82] ./~/orbit-db-counterstore/src/CounterStore.js 2.12 kB {0} [built]
  [85] ./~/orbit-db-kvstore/src/KeyValueStore.js 2.27 kB {0} [built]
  [70] ./~/core-js/library/modules/_task.js 2.28 kB {0} [built]
   [7] ./~/core-js/library/modules/_export.js 2.31 kB {0} [built]
  [97] ./~/orbit-db-pubsub/src/ipfs-pubsub.js 2.35 kB {0} [built]
  [83] ./~/orbit-db-docstore/src/DocumentStore.js 2.82 kB {0} [built]
  [63] ./~/core-js/library/modules/_iter-define.js 2.82 kB {0} [built]
  [81] ./src/Cache.js 2.92 kB {0} [built]
 [104] ./~/base64-js/lib/b64.js 3.57 kB {0} [built]
  [26] ./~/orbit-db-store/src/Store.js 4.26 kB {0} [built]
  [54] ./~/orbit-db-eventstore/src/EventStore.js 4.29 kB {0} [built]
  [89] ./~/ipfs-log/src/entry.js 4.38 kB {0} [built]
 [153] ./~/idb-pull-blob-store/lib/index.js 4.46 kB {0} [built]
 [191] ./src/OrbitDB.js 5.81 kB {0} [built]
 [160] ./~/path-browserify/index.js 6.18 kB {0} [built]
 [186] ./~/setimmediate/setImmediate.js 6.47 kB {0} [built]
  [92] ./~/logplease/src/index.js 8.08 kB {0} [built]
  [36] ./~/events/events.js 8.33 kB {0} [built]
 [149] ./~/core-js/library/modules/es6.symbol.js 8.93 kB {0} [built]
 [148] ./~/core-js/library/modules/es6.promise.js 10 kB {0} [built]
  [90] ./~/ipfs-log/src/log.js 15.6 kB {0} [built]
 [189] ./~/util/util.js 15.6 kB {0} [built]
  [20] ./~/node-libs-browser/~/buffer/index.js 48.6 kB {0} [built]
 [152] ./~/dexie/dist/dexie.js 199 kB {0} [built]
    + 1 hidden modules
Build success!

Using webpack@2.2.1 and UglifyJS#harmony.

Comes from:

samuli:~/code/orbit-db$ npm ls dexie
orbit-db@0.16.3 /Users/samuli/code/orbit-db
└─┬ idb-pull-blob-store@0.5.1
  └── dexie@1.5.1
dignifiedquire commented 7 years ago

@haadcode could you test with this branch: https://github.com/ipfs/js-idb-pull-blob-store/pull/17 this uses the latest dexie and directly uses the minified version

haadcode commented 7 years ago

Will do. Will also try with babili as discussed if the latest dexie still shows up big.

haadcode commented 7 years ago

From IRC:

05:39 <+haad> dignifiedquire: lol, I found what was causing the weirdness re. the bundle sizes!
05:39 <+haad> dignifiedquire: with webpack@2, you now need to run 'webpack -p' to *actually* build a minified bundle
05:39 <+haad> dignifiedquire: so the numbers I was looking at yesterday were actually unminified files :D
05:39 <@dignifiedquire> oO
05:40 <+haad> yup
05:41 <+haad> so you were right, they were nonminified sizes :)

So to sum it, with webpack 2, we need to run it with -p flag in order to produce minified builds, and the numbers webpack 2 show upon build are non-minified sizes.

I think we can close this. Agreed @dignifiedquire?

haadcode commented 7 years ago

Oh, one more:

05:58 <+haad> dignifiedquire: oh, hmm, maybe spoke too soon. with the default webpack@2.2.0 install, it doesn't minify it down to 28kb, but when I have uglify#harmony installed, it does.

So, make sure to include "uglify-js": "github:mishoo/UglifyJS2#harmony" in your package.json

daviddias commented 7 years ago

dexie is going away with new datastore, so no more worries :)

Closing this one!