-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could be made more treeshakeable #65
Comments
Out of curiosity, what it is the use case for minimizing to just the encoder? I designed this with the expectation that generally if you want a minimal single module, it would be for decoding messages in the browser.
Generally, differences approaches tend a look a lot cleaner from a distant. But I think the real issue is the public API itself is designed such that I think perhaps are more feasible approach might be to have a pack-only.js module that is generated from pack.js, but with the imports from unpack.js replaced with no-ops. You could then import something like msgpackr/pack-only.js to have an encode-only msgpackr module. Would that be a reasonable solution for your use case? |
Hi, But this should be no different than passing data from any api to another. Msgpackr is fast. :). But since i have to create a new v8 engine and reparse the scripts on each call, parse size becomes a virtue. |
My thought was to break the Unpackr out into a separate module sucj as Ctx and then let Unpackr be Ctx plus the different pure functions with the Ctx bound as needed. Then pack and unpack would be trivial to expose as separate modules implementing the corresponding functions with default state bound. But i understand that it might be out of scope. If i get time i might give it a shot. Also imo typescript would be pretty sweet. |
MsgPackr is fast but when you only need a part of it, its doesn't treeshake very well,
exporting and minifying only encode() yields a file size of about 21 KB while as a comparison the same with @msgpack/msgpack yields a file size of about 10Kb.
I believe this stems from msgpackr's architecture where the Unpackr object is the base object also for unpack functionality and on top of that the Packr object declares most of its functions as private functions inside its constructor through functions scoped variables.
A possible step that might also be easier for the V8 to optimize would be to go with a cleaner more functional approach. Just make all functions take a well defined context object (to avoid poly/ megamorphism) Then there can be some global state objects like the defaults and also some classes to instanciate which then uses these functions if that is what you want.
I believe this would make it much more treeshakeable / modular and possibly faster (but the V8 us magic so you never know).
The text was updated successfully, but these errors were encountered: