performance: cache existsSync results in PackageCache.ownerOfFile #1612
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.
Similar to #1608
A lot of time is being spent in
PackageCache#ownerOfFile
and a good chunk of that is from the calls toexistsSync
:Before:
![Screenshot 2023-09-25 at 11 17 06 PM](https://private-user-images.githubusercontent.com/20404/270526344-50c4e7ad-7c41-48b2-ae22-43e6c2e6aa5f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4NjM1MTQsIm5iZiI6MTczODg2MzIxNCwicGF0aCI6Ii8yMDQwNC8yNzA1MjYzNDQtNTBjNGU3YWQtN2M0MS00OGIyLWFlMjItNDNlNmMyZTZhYTVmLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDE3MzMzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA3ZTdkMzMzY2VhNDllMmJlN2U3ZTUxOGNkNjgzN2NmMDE5MDk2Yjk5MzJjMTY1MzU1ZjM3NGM1ZWFhYzFjYTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2PJDU_T-it8KFEUzDCE-PCvAqSSNnw1kPVbzQxuFdt8)
By caching, the amount of time in
existsSync
drops considerably in my large app, From ~12 seconds to under 500ms. The total time spent inownerOfFile
drops less, from 20 to 14 seconds.After:
![Screenshot 2023-09-25 at 11 17 18 PM](https://private-user-images.githubusercontent.com/20404/270526685-7b88d32b-6f91-4aee-8207-02255800f612.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4NjM1MTQsIm5iZiI6MTczODg2MzIxNCwicGF0aCI6Ii8yMDQwNC8yNzA1MjY2ODUtN2I4OGQzMmItNmY5MS00YWVlLTgyMDctMDIyNTU4MDBmNjEyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDE3MzMzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVmZmVkMWIwYWU0ZmNjY2IwYTA5ZmQ2NzkyZDIyOWU0OTM2M2IwMzZmODhjMzZhNTI5YjFhNmY0ODQ1NzQ2ZDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.35Y9ZvNnbWXRCpa7iepMH-KPk8QGcik_HuIN6Q_Qg0Q)
Even with the caching, this path is still so hot that there's a good deal of time in
ownerOfFile
and the newgetCachedExistsSync
methods that isn't accounted for byexistsSync
. There's probably more that can be done here.