Gruntfile: Optimize verify:source-maps #9
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.
The
verify:source-maps
check runs serially both to find the set of files to check as well as to scan those files. Additionally, it loads the entire contents of those files into memory when running and then performs a full text search across the contents in memory.In this patch we're refactoring that check to run asynchronously. It concurrently calls the
glob
function to search for the files to scan, and then concurrently scans those files files one 64 KB chunk at a time to look for the source map text.This concurrency should eliminate some IO bottlenecking and the chunking might drop the memory use if the previously loaded files are large enough. Now, memory use should correspond to roughly 64 KB times the number of concurrently opened files that are being scanned.
Interestingly, with
N = 20
, there's no meaningful change in performance, and the script executes too fast for me to watch the CPU core activity.# on darwin /usr/bin/time -l npx grunk verify:source-maps
Mean values.
trunk
The user/system/real times didn't show any noticeable change either, which is likely because the runtime is dominated by
grunt
bootup time. This may be the same cause for the other metrics appearing unchanged.The involuntary context switches surging in this branch are probably the result of the IO concurrency switching tasks while waiting on file IO.