Bug report
Bug description:
Parsing a large mbox file with mailbox.mbox is surprisingly slow and I did some profiling and debugging. For a large file (my testcase, 3,000 mails, 26,000,000 lines), somewhere around half the time is spent calling tell(), once per line in PartialFile. As documented in issue #107158, tell() here uses lseek which is a system call rather than just returning a constant.
# Slow code, assuming a large my_mail.mbox
import mailbox
box = mailbox.mbox("my_mail.mbox", create=False)
for message in box:
pass
Replacing mailbox.mbox with a simple mmapped file that scans for b"\nFrom " and calls BytesParser(policy=policy.default).parsebytes(...) directly gives the same results in my testing (I'm sure it's not as powerful). In my tests that cuts the parsing overhead from 11 seconds to 1, and total parse time from >20 to 9.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
Bug report
Bug description:
Parsing a large mbox file with mailbox.mbox is surprisingly slow and I did some profiling and debugging. For a large file (my testcase, 3,000 mails, 26,000,000 lines), somewhere around half the time is spent calling tell(), once per line in PartialFile. As documented in issue #107158, tell() here uses lseek which is a system call rather than just returning a constant.
Replacing mailbox.mbox with a simple mmapped file that scans for b"\nFrom " and calls
BytesParser(policy=policy.default).parsebytes(...)directly gives the same results in my testing (I'm sure it's not as powerful). In my tests that cuts the parsing overhead from 11 seconds to 1, and total parse time from >20 to 9.CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs