Skip to content

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

@seenaburns

Description

@seenaburns

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 rescript-lang/rescript/pull/2171 or rescript-lang/rescript/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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions