sindresorhus / trash

Move files and directories to the trash
MIT License
2.58k stars 79 forks source link

Improve performance on Linux #90

Closed stroncium closed 4 years ago

stroncium commented 5 years ago

Fixes #79

When actual move is performed(not just rename), the speed is mostly bound by IO, code details have minor effect, both for directories and for singular/multiple files.

When rename happens(majority of the cases), moving directory is almost the same as moving single file. So, I used simplistic benchmark for various number of files.

Before:

bench "1 file" took 0.186s
bench "10 files" took 0.222s
bench "100 files" took 0.619s
bench "1000 files" took 7.875s
bench "5000 files" took 80.94s

After:

bench "1 file" took 0.133s
bench "10 files" took 0.138s
bench "100 files" took 0.166s
bench "1000 files" took 1.719s
bench "5000 files" took 39.776s

Note, that the part that actually trashes files takes only around 0.6s out of bench "5000 files" took 39.776s case, remaining time is spent processing data prior to passing control to linux-specific code.


IssueHunt Summary ### Referenced issues This pull request has been submitted to: - [#79: Improve performance on Linux](https://issuehunt.io/repos/19789032/issues/79) --- IssueHunt has been backed by the following sponsors. [Become a sponsor](https://issuehunt.io/membership/members)
sindresorhus commented 4 years ago

Awesome! And nice work as always 💃