rakshasa / rtorrent

rTorrent BitTorrent client
https://github.com/rakshasa/rtorrent/wiki
GNU General Public License v2.0
4.05k stars 412 forks source link

Optimization opportunity for hash checks of partially downloaded files #1255

Open loskutov opened 6 months ago

loskutov commented 6 months ago

Operating systems provide APIs (FIEMAP ioctl in case of Linux, who really cares about others) to get the information regarding underlying FS extents of a file, including whether the extent is zero-initialized and never touched afterwards (FIEMAP_EXTENT_UNWRITTEN). For the pieces that are located inside such extents, it's obvious in advance that sha(block) = sha('\0' * block_size), so the SHA computation can be bypassed. It can significantly improve recheck times in cases when rtorrent was killed while downloading.