Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gruntfile: Optimize verify:source-maps #9

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dmsnell
Copy link
Owner

@dmsnell dmsnell commented Jun 27, 2023

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.

Measure trunk this branch change
maximum resident set size 210848972.8 219451392 +4.08%
peak memory footprint 2157075.2 2137411.2 -0.92%
cycles elapsed 18917476.15 19269419.5 +1.86%
page reclaims 17786.4 18309.1 +2.94%
voluntary context switches 9.15 9.1
involuntary context switches 1360 5851.4

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant