Introducing binaryen-loader

in utopian-io •  7 years ago 

Repository

RepositoryLink
binaryen-loaderhttps://github.com/DrSensor/binaryen-loader
Example Projecthttps://github.com/DrSensor/example-vue-component-rust

About binaryen-loader

Binaryen is a compiler and toolchain infrastructure library for WebAssembly, written in C++. Most of the tools are cli app and one of them can be embedded into javascript (binaryen.js). This project is just a webpack loader that wraps binaryen.js (only the optimization parts) so it can be chained easily with other webpack-loader. For more insight see this tutorial in section Using Binaryen.

example usage
chaining binaryen-loader with other webpack loader

Current features

Since this project based on binaryen.js, most of the features are just wrappers from module-optimization section. Some of the features are:

  • define optimization flags in options.optimization
  • run specific passes by defining it in options.transformation.passes (sometimes it can shrink the bundle size, sometimes it can increase the execution speed, sometimes it does the opposites for both of them)
  • enables debug information in emitted wasm code by setting the options.debug to true

Technology Stack

Since this project generated from webpack-defaults with some modification (see commit before v0.0.2), the tech stack used is what webpack-defaults proposed.

TaskTech/ToolConfiguration
Package Managernpm (not yarn)package.json
Test FrameworkJestjest.config.js, jest.setup.js
Linter and othersESLint, Prettier, husky.prettierrc, .eslintrc.js, lint-staged, commitlint.config.js
Release Toolhusky, standard-version
Build Tool (Transpiler)Babel.babelrc
CIcircleci.circleci/config.yml

Some interesting things to note

  • ✨ There is helper file I created to make the testing enjoyable called on.js. For people who wrote some of webpack-loader, maybe you want to copy and edit that file 🐣

on.js usage
on.js in action

jest_node10_bug
comparison of snapshot generated by .toThrowErrorMatchingSnapshot(). Left: generated when running on node:10. Right: generated when running on node:8 and node:6

manual_approval demo
using Manual Approval feature on binaryen-loader workflow

  • ✅❔ There is fix attempt for timeout problem as shown below. Not sure if the fix is because running jest with --ci flag or set testEnvironment: 'node' (since by default testEnvironment is jsdom). Maybe adding jest.config.js override jest configuration in package.json (making it invalid).

timeout problem
timeout problem when running on CI. Fix on commit 33123b0

  • 💩 Since conventionalcommits take to much space on commit message, I try to combine it with gitmoji convention. Not sure if it's a good idea 😆

gitmoji+conventionalcommits
new combo: gitmoji + conventionalcommits

Future Plans

  • Currently, using passes like print-call-graph that is print the call-graph to stdout will pollute webpack outputted message. I plan to pipe the output into a file but still don't have a clue how to do it. Feel free to make PR, open an Issue, or just comment below if anyone has an idea 🙂
  • There is an idea to separate some passes into categories (issue #2). Still evaluating and looking some feedback for this.
  • I do document some behavior of some configuration in a form of unit-tests, like the provided export it exposed and range of binary size of wasm code after running Binaryen. I will continue this effort when finding something interesting along the way. Feel free to make PR (adding fixture and/or test case) if anyone found something interesting 🙂
  • Add test case when chained to another loader, especially from foreign programming language (e.g Rust using rust-native-wasm-loader).

How to contribute?

The project is open to contributions in any way possible. If you find a bug, please open an issue in the project's issue tracker. For submitting code patches, feel free to open pull requests on Github. Read CONTRIBUTING.md first for the best experience 😄

GitHub Account

https://github.com/DrSensor

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  • Great post, you're clearly a master of markdown and emojis!
  • Could this be used for EOS development?

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

  ·  7 years ago (edited)

Thank you @helo. After looking at this, I think it's possible to use it in EOS development especially when targeting web browser (not sure about nodejs). The workflow would be:

Selection_029.png

However, if the purpose is just to get smaller or optimized wast file, it is better to use wasm-opt. The workflow would be:

Selection_030.png

Hey @drsensor
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Congratulations @drsensor! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @drsensor! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on the badge to view your Board of Honor.
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @steemitboard!


Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!