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

perf: check existsSync before calling unlinkSync #156

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

Conversation

raycohen
Copy link

@raycohen raycohen commented Oct 10, 2023

unlinkSync is very expensive when it throws, which it will do if existsSync returns false for the path. In my large ember app this gets hit a lot. Note that almost all of the time spent in unlinkSync comes from error handling, which is only needed when unlinkSync would throw. Adding this guard shaves about 4 seconds off of the 21 seconds spent in _copy. I suspect there are more performance improvements to be made here.

These tests were done with node v16.16. The fs error handling behavior/perf might vary across node versions.

Before:
unlinkSync takes 4.9s of 21s in _copy
Screenshot 2023-10-09 at 10 13 51 PM

After:
unlinkSync takes 0s of 17s in _copy
Screenshot 2023-10-09 at 10 03 09 PM

@raycohen raycohen marked this pull request as ready for review October 10, 2023 02:28
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.

None yet

1 participant