This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mxmlnkn
Recipients mxmlnkn
Date 2020-06-02.15:18:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591111102.48.0.378396019382.issue40843@roundup.psfhosted.org>
In-reply-to
Content
Consider this example replicating a real use case where I was downloading the 1.191TiB ImageNet in sequential order for ~1GiB in order to preview it:

echo "foo" > bar
tar cf sparse.tar bar


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import tarfile
import time

t0 = time.time()
for tarInfo in tarfile.open( 'sparse.tar', 'r:', ignore_zeros = True ):
    pass
t1 = time.time()
print( f"Small TAR took {t1 - t0}s to iterate over" )

f = open( 'sparse.tar', 'wb' )
f.truncate( 2*1024*1024*1024 )
f.close()

t0 = time.time()
for tarInfo in tarfile.open( 'sparse.tar', 'r:', ignore_zeros = True ):
    pass
t1 = time.time()
print( f"Small TAR with sparse tail took {t1 - t0}s to iterate over" )


Output:

Small TAR took 0.00020813941955566406s to iterate over
Small TAR with sparse tail took 6.999570846557617s to iterate over


So, iterating over sparse holes takes tarfile ~300MiB/s. Which sounds fast but is really slow for 1.2TiB and when thinking about it as tarfile doing basically >nothing<.

There should be better options like using os.lseek with os.SEEK_DATA if available to skip those empty holes.

An alternative would be an option to tell tarfile how many zeros it should at maximum skip.
Personally, I only use the ignore_zeros option to be able to work with concatenated TARs, which in my case only have up to 19*512 byte empty tar blocks to be skipped. Anything longer would indicate an invalid file. I'm aware that these maximum runs of zeros vary depending on the tar blocking factor, so it should be adjustable.
History
Date User Action Args
2020-06-02 15:18:22mxmlnknsetrecipients: + mxmlnkn
2020-06-02 15:18:22mxmlnknsetmessageid: <1591111102.48.0.378396019382.issue40843@roundup.psfhosted.org>
2020-06-02 15:18:22mxmlnknlinkissue40843 messages
2020-06-02 15:18:21mxmlnkncreate