Add possibility for disabling inlining wasm in opencv.js#23344
Add possibility for disabling inlining wasm in opencv.js#23344asmorkalov merged 1 commit intoopencv:4.xfrom
wasm in opencv.js#23344Conversation
| parser.add_argument('--emscripten_dir', default=emscripten_dir, help="Path to Emscripten to use for build (deprecated in favor of 'emcmake' launcher)") | ||
| parser.add_argument('--build_wasm', action="store_true", help="Build OpenCV.js in WebAssembly format") | ||
| parser.add_argument('--disable_wasm', action="store_true", help="Build OpenCV.js in Asm.js format") | ||
| parser.add_argument('--disable_single_file', action="store_true", help="Do not merge JavaScript and WebAssembly into one single file") |
There was a problem hiding this comment.
I think it make sense highlight wasm in the flag naming. Something like --disable_wasm_merge or --build_standalone_wasm.
There was a problem hiding this comment.
However, origin option is SINGLE_FILE so it's also logical to keep --disable_single_file 🤔
There was a problem hiding this comment.
Agree, pros and cons, no strong opinion from my side on argument name 🙂 If we are to move away from single_file in the argument name I think I personally like your second suggestion the best, i.e. --build_standalone_wasm (we then avoid the word disable, which maybe makes the argument name slightly easier to interpret by removing a negation).
Happy to modify the PR if you decide on some other name instead of --disable_single_file.
| -# The build script builds asm.js version by default. To build WebAssembly version, append `--build_wasm` switch. | ||
| By default everything is bundled into one JavaScript file by `base64` encoding the WebAssembly code. For production | ||
| builds you can add `--disable_single_file` which will reduce total size by writing the WebAssembly code | ||
| to a dedicated `.wasm` file which the generated JavaScript file will automatically load. |
There was a problem hiding this comment.
Can this approach fix this issue as well? #21431. Which size reduction do you observe?
There was a problem hiding this comment.
- Single file: 8.74 MB
.js - Separate
.wasmfile: 170 kB.js+ 6.43 MB.wasm
I.e. bundling the generated webassembly code with base64 is ~32-33 % larger in total compared with separate .wasm file (consistent with typical base64 encoding size increases).
Closes #22530 and also related to #15315.
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.