Add check for .env.local and module bindings generations to only write on changes #3604
+8
−2
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.
Description of Changes
The
spacetime devandspacetime generatecommands always overwrite the.env.localandmodule_bindingsfiles, even if the contents are identical. This can be a nuisance if your client is watching for changes and reloading, asspacetime devwill modify both of those at different times in the process.This change will first read the contents of the files and see if a write is necessary.
For writing
.env.localas part ofspacetime dev, the file contents were already read so no real impact should exist.For
module_bindings, I've done some initial profiling with 181 generated typescript files and separately 161 rust files and noticed no performance impact.API and ABI breaking changes
None
Expected complexity level and risk
1
Testing
I've ran this code on a project that generates 181 source files for typescript and 161 for rust. It correctly writes files when changes have been made and leaves the files unmodified if no changes are made.
For review testing, I would recommend running both with and without my change on a much more complex project if it's available. I would think not writing the contents of each file would mitigate the cost to read most of the time, but perhaps in certain project makeup scenarios and storage performance characteristics, this could possible be marginally slower sometimes, though I have not observed that to be the case.