Dead code elimination in Example#962
Dead code elimination in Example#962kidandcat wants to merge 1 commit intomaxence-charriere:masterfrom
Conversation
Because Go compiler has dead code elimination, if we encapsulate the backend code in this if, as it is based on a constant value, the compiler will remove all code related to what's inside the if when compiling for wasm, leading to considerable size reduction. (In my playground app it reduces size from 21MB to 17MB uncompressed)
|
This is very interesting We use build tags for all larger project to separate backend and frontend code, so this has no effect. But I tested it with https://github.com/oderwat/go-guess-the-number-app, and it reduces P.S.: I tried to use the same concept on our much larger apps and found that it does reduce the size also considerably but using build tags reduces the size even more. In one example with a private project (AI frontend) of mine I get 21 MB without any optimization, 8.3 MB using P.P.S.: Using the build tag is demonstrated here: |
Because Go compiler has dead code elimination, if we encapsulate the backend code in this
if, as it is based on a constant value, the compiler will remove all code related to what's inside thatifwhen compiling for wasm, leading to considerable size reduction.(In my playground app it reduces size from 21MB to 17MB uncompressed)