satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
56 stars 13 forks source link

--preload-file is more efficient than --embed-file #165

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

http://kripken.github.io/emscripten-site/docs/tools_reference/emcc.html#emcc-embed-file says "Embedding files is much less efficient than preloading them", and indeed it generates a huge JavaScript array in craft.js even in the release build:

var Module;if(typeof Module==="undefined")Module={};if(!Module.expectedDataFileDownloads){Module.expectedDataFileDownloads=0;Module.finishedDataFileDownloads=0}Module.expectedDataFileDownloads++;((function(){var loadPackage=(function(metadata){function runWithFS(){Module"FS_createPath";Module"FS_createPath";var fileData0=[];fileData0.push.apply(fileData0,[35,105,102,100,101,102,32,71,76,95,69,83,10,112,114,101,99,105,115,105,111,110,32,109,101,100,105,117,109,112,32,102,108,111,97,116,59,10,112,114,101,99,105,115,105,111,110,32,109,101,100,105,117,109,112,32,105,110,116,59,10,35,101,110,100,105,102,10,10,117,110,105,102,111,114,109,32,115,97,109,112,108,101,114,50,68,32,1...

Should switch to --preload-file, and include the extra .data file

satoshinm commented 7 years ago

A nice space savings, before:

release-build-js $ ls -lh craft.*
-rw-r--r--  1 admin  staff   101K May 27 17:58 craft.html
-rw-r--r--  1 admin  staff    19K May 27 17:58 craft.html.mem
-rw-r--r--  1 admin  staff   1.4M May 27 17:58 craft.js

after:

release-build-js $ ls -lh craft.*
-rw-r--r--  1 admin  staff   241K May 27 18:00 craft.data
-rw-r--r--  1 admin  staff   101K May 27 18:00 craft.html
-rw-r--r--  1 admin  staff    19K May 27 18:00 craft.html.mem
-rw-r--r--  1 admin  staff   624K May 27 18:00 craft.js

624 + 241 = 865 KB, less than the 1.4 MB craft.js from before due to inefficient encoding