Check for existing results to rebuild #123
Merged
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.
Currently, this plugin calls the ESBuild
build
method each time a file is changed.As documented in #98, this behavior results in exponentially increasing memory usage as files are changed. Personally, I saw my memory usage (from the esbuild process) spike from an initial value of 600 MB to 2GB after just 5 changes. Ultimately, the memory usage results in a fatal error, where the JavaScript heap runs out of memory.
What I did
In this pull request, I've added a conditional check in the
bundle
method to callrebuild
instead ofbuild
if there are existing build results.I also set the
bundle
method to enable incremental builds by default. From what I understand, the way the ESBuild process works is as documented here:incremental: true
.rebuild
on the existing build result.Results
With the change in this PR, memory usage increases much more slowly. After about 10 file changes, the memory only increased to about 1GB (I noticed a linear increase of about 30MB each time). Further debugging is needed to determine the source of that slight memory usage increase, but it seems like this optimization addresses the majority of the existing increases in memory usage.