Skip to content

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.

1 participant