-
Notifications
You must be signed in to change notification settings - Fork 299
Bundling js-ipfs-api #353
Comments
ConsenSys is using https://github.com/pelle/browser-ipfs for their IPFS wrapper. Their reason is simply the size: 900kb (js-ipfs-api) vs. 2kb (browser-ipfs). @diasdavid @dignifiedquire this begs the question: why is js-ipfs-api so large? What are the dependencies that make it so large? If js-ipfs-api can't use less dependencies, should we talk about a light api lib, much like browser-ipfs? |
@diasdavid said:
|
That would be sweeeeeet! |
Another comment that was related to this: Some feedback from elsewhere (cc @pelle). @diasdavid @dignifiedquire make sure to note the comment re. dependencies.
|
It is important to note, that browser-ipfs does not nearly implement the full api, where as js-ipfs-api aims to implement the full spectrum. That said I believe there is a lot we can do to reduce the size, but probably not down to 2kb :) |
Dependency analysis with the latest
|
My general beef with most of the JS code in the ethereum world and I guess also the IPFS world is the reliance on node infrastructure and many, many dependencies. I think the reason being is that it's easy to develop libraries on this, but also the IMHO mistaken belief that having code that works on both node and in the browser is a good thing. Size is the most obvious problem here, for example instead of using the browsers built in networking libraries much of what is implemented in these many dependencies are things that already exist. They may not be as good, but they do the trick for pretty much all browser cases, because in the end thats what is used under all the dependencies and fancy facades anyway. So if the primary reason for creating The less obvious problem is fragility, due to so many dependencies, duplicated dependencies, multiple libraries that do the same thing. Each of these libraries causing problems with browserify, webpack what have you. So I know and understand thats how node work and it works well in a simple uniform environment like the v8. But with all the different browsers and now also things like React Native it is a literal nightmare interacting with these libraries. The most important thing I think the IPFS community can do is fully document the http api well. Interacting with http is the lowest common denominator and any good web developer understands how to do this. My browser-ipfs shows that for most cases it's not necessary to be particularly complex. Secondly different classes of js api's need to be created. This project I only just learnt about yesterday, so I'm learning about it now and may not understand much about it yet. But the needs of people interacting from the browser and from doing ipfs server integrations are very different. Anyway I'm happy to help out and will attempt to make |
cc @RichardLitt for http api docs comments above |
@dignifiedquire im not sure why these are necessary. You could prob drop 30% on crypto libraries alone! # okay why is there an impl of (what i can only guess is) ECC
elliptic: 304.63 KB (14.2%)
# i imagine this is here because of the crypto libs
bn.js: 170.29 KB (7.97%)
readable-stream: 146.03 KB (6.83%) # wow that's big.
asn1.js: 126.35 KB (5.91%) # why do we need asn1.js encoding? TLS?
# more crypto stuff... why? TLS?
des.js: 40.69 KB (1.90%)
diffie-hellman: 35.13 KB (1.64%)
browserify-sign: 29.14 KB (1.36%)
ripemd160: 11.91 KB (0.557%)
create-ecdh: 7.49 KB (0.350%) |
@jbenet yes this is a known issue with our current set of crypto libraries, neither forge nor browserify-crypto are modular. This means using a single crypto function (in this case sha2 from multihashing) imports the complete! crypto library. In this specific case we could replace https://github.com/multiformats/js-multihashing/blob/master/src/index.js#L4 with direct imports to |
I was looking through the code trying to find out where the digest code is called and it seems just from my skimming around to be wherever the If they do then perhaps a lightweight version of the library can be generated using webpack or browserify with only the higher level apis which would solve the majority of these issues. I agree a good clean sha implementation with only a few dependencies is important. I'll see if I can help with that, since at least that part I do understand :-). |
Sorry I just realized that sha.js will do exactly that. @dignifiedquire replacing that line as you suggest will absolutely be a huge help. That may even let me use it on ReactNative. |
@pelle I think this is something we can do easily in the next days. For long term improvements I have just written up something here ipfs/js-ipfs#398 (comment) and would value any feedback :) |
Just created above PR to help on that side. I'll have a look at the other comment @dignifiedquire |
Great! Yeah definitely rip out only the things you need.
|
Replacing |
👍 |
This is coming! :D
Main tracking issue: ipfs/js-ipfs#429 (covers both js-ipfs and js-ipfs-api) |
We shipped the major parts of this. Which reduces the minified bundle size down to |
All of the tasks for this issue are now complete and we have two awesome examples you can check out and try by yourself the new easy bundling, find them here: https://github.com/ipfs/js-ipfs-api/tree/master/examples Closing this issue but feel free to reopen if you encounter any other hurdles :) |
We should explore the options and solutions to reducing the size of the distributed build of js-ipfs-api (
dist/index.min.js
).Originally started here: ipfs/js-ipfs#398.
As it stands today, the dist file is at ~900kb. How far can we go? :)
The text was updated successfully, but these errors were encountered: