Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On large react applications (~1000 chunks), i get some
R10
errors because of the app isn't able to boot within 60 seconds.Looking at the logs, it seems that the buildpack is trying to inject the configuration during this timeframe and it takes a few hundreds ms per file on average.
This is what a typical trace looks like
By looking at the script, it looks like it loads a new ruby VM for each files in the bundle, which can be really slow
ruby -E utf-8:utf-8 \ -r /app/.heroku/create-react-app/injectable_env.rb \ -e "InjectableEnv.replace('$js_bundle_filename')"
By disabling the loading of the gems on startup, i managed to decrease a bit the execution time for
ruby-1.9.3
which is the version used by this buildpack:ruby -E utf-8:utf-8 \ -r /app/.heroku/create-react-app/injectable_env.rb \ -e "InjectableEnv.replace('$js_bundle_filename')" \ --disable-gems
With the gems autoloading enabled (on a macbook pro with 4 cores and 1000 js files)
time .profile.d/inject_react_app_env.sh .profile.d/inject_react_app_env.sh 13.07s user 6.86s system 90% cpu 22.003 total
Without:
time .profile.d/inject_react_app_env.sh .profile.d/inject_react_app_env.sh 9.97s user 7.24s system 83% cpu 20.686 total
Fun fact, ruby 3.0 is way slower than 1.9.3 to start, so this patch is even more important
With gems:
time .profile.d/inject_react_app_env.sh .profile.d/inject_react_app_env.sh 58.70s user 14.98s system 93% cpu 1:18.48 total
Without:
time .profile.d/inject_react_app_env.sh .profile.d/inject_react_app_env.sh 12.23s user 8.16s system 84% cpu 24.011 total
My gut feeling is that on a typical dyno where the I/O are a bit slow than on my local machine, it can have a big impact and reduce the amount of time spent on the inject variable stage.
I will also try to reduce the number of files inspected in another PR.