Open Hurtak opened 5 years ago
Hi @Hurtak,
Thanks for taking the time to raise this.
At the outset, I'd like to say monitoring bundle size is not something I am particularly strong in. I have looked into the best way of tracking it a couple of times and have never really come away with a clear answer.
But if you'll permit me, I'd like to run through a few reasons why version 2.0.0 is indeed significantly larger than v1.1.4.
With the removal of mousetrap, react-hotkeys
now handles all key map detection and matching. So I have had to effectively replace mousetrap's entire functionality. This was done to better integrate with React, and to lean on its key standardisation and synthetic event system. I wonder if the ways you're using to measure the bundle size subtract the size of mousetrap.
v2.0.0 also provides a significant number of optimisations, bugfixes and additional functionality - this unfortunately does require additional code. The release notes give a good overview of those.
As bundle size has been something I've tried to be mindful of, a number of steps have been taken to attempt to reduce it:
"files"
attribute is used in package.json to ensure only essential files are included in the published bundle."modules"
package.json attribute points to a ES6 module release that should allow tree shaking, and only including the files that are actually required by the consuming project. (This is something I don't have a confident understanding of, so it may not be functioning as intended).There are a few things I can try, to get the bundle size down:
react-hotkeys
is being built with the most up-to-date ES5 transpilation algorithms.There is also (hopefully) good news that the bundle will get slightly smaller in subsequent versions:
Please let me know if you have any other ideas or thoughts on how the bundle size may be reduced further.
Hi,
thanks for the detailed answer and for the hard work on this great library!
I think you are doing everything right when it comes to optimization, the only thing that comes to mind would be some lightweight build that would cover only some basic functionality (not sure if that would actually help) but I think this library is not that big to have this additional complexity justified. We will see what happens at 3.0 that will remove the deprecated features.
Cheers
Yes, a possibility I forgot to mention is that parts of the library may be able to be abstracted into optional plugin packages. At the moment, react-hotkeys
isn't set up for plugins, and the things that come to mind for abstraction are the legacy backwards compatible components. But there may be something that makes itself known as I continue to think about it.
Similarly, I don't think there is currently much to jettison for a stripped down version. I also don't particularly like the idea of maintain two libraries, when I can barely keep up with one.
But I'm open to suggestions on optional features that may be spun off, and are worth the hassle of doing so when it comes to bundle size.
Thanks for putting this back on my radar. I shall endeavour to find a more consistent and systematic way of tracking bundle size in the future so it remains at the forefront of my mind.
Let me know if you'd like a hand with this. My team has been working hard on bundle optimizations and we'd actually like to use this library if it weren't for the bundle size. Every byte makes a difference for us. I'd be happy to help out if it could lead to use implementing react-hotkeys in our product.
Hi,
It seems that the bundle size difference of 2.0.0 vs 1.1.4 is 3x in minified code size and 2x in min+gzip which seems like a lot.
Stats reported from import cost plugin in VS Code
Stats from my CRA application after updating to 2.0.0
I wonder if the bundle size could be cut down closer 1.x.x sizes.