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

Find more stable way of including bs-platform/lib/js/* #19

Open
seenaburns opened this Issue Jul 31, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@seenaburns
Copy link
Owner

seenaburns commented Jul 31, 2018

Problem

Isolate's startup time on Windows became abysmally slow (~30-60s) after adding React and Reason as dependencies.

Investigating, I found the app had high disk activity, and appeared to be creating a new directory under ~/AppData/Local/Temp/... that would contain the unpacked asar, with just 300mb of bs-platform. The exe was only 60mb, so I suspect on EVERY startup it was unpacking, compiling the bs-platform tooling, and then deleting it after the app closes, but I would need to do more investigation.

Unfortunately bs-platform does not expose the runtime libraries as a separate package, so the only way to include these dependencies (for example bs-platform/lib/js/array.js) is to include all of bs-platform

Workaround

505d159 includes a janky addition to build.sh which copies out bs-platform/lib/js/*.js and reason-react into local modules, includes them in the electron-builder build and replaces all references to the bs-platform module with local modules.

# From build.sh
replace_deps() {
    sed -i '' "s|require(\"$1|require(\"$2|g" $3;
}

if [ ! -d build/bs-stdlib ]; then
    mkdir -p build/bs-stdlib/lib/js
    cp -r node_modules/bs-platform/lib/js/* build/bs-stdlib/lib/js/
fi

if [ ! -d build/reason-react ]; then
    mkdir -p build/reason-react/src/
    cp -r node_modules/reason-react/src/*.js build/reason-react/src/
    for f in $(find build/reason-react -iname '*.js'); do
        replace_deps "bs-platform" "../../../build/bs-stdlib" $f
    done
fi

for f in $(find src -iname '*.bs.js'); do
    replace_deps "bs-platform" "../build/bs-stdlib" $f
    replace_deps "reason-react" "../build/reason-react" $f
done

Better solution

Ideally BuckleScript/bucklescript/pull/2171 or BuckleScript/bucklescript/issues/2127 will separate bs-platform's Javascript stdlib into a separate package. This would be preferable because the *.bs.js files and any other libraries (e.g. reason-react) reference bs-platform. Changing the compilation of these files seems more stable than hacking at the require references afterwards.

Short of that, maybe there's a more stable way of doing this in the build. Maybe replacing require references is what webpack is for, and could make vendoring these libraries easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment