gh-157509: Avoid a tell() per line when indexing mbox, MMDF and Babyl files by eendebakpt · Pull Request #157543 · python/cpython · GitHub
Skip to content

gh-157509: Avoid a tell() per line when indexing mbox, MMDF and Babyl files - #157543

Open
eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:gh-157509-mbox-toc-no-tell
Open

eendebakpt wants to merge 1 commit into
python:mainfrom
eendebakpt:gh-157509-mbox-toc-no-tell

Conversation

@eendebakpt

@eendebakpt eendebakpt commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

By replacing tell() with a simple counter next_pos and hosting separator construction out of the look performance of reading a mailbox is improved by a factor 2x.

Track line offsets in _generate_toc() with len(line) instead of calling
tell(), which is a system call, for every line.  Also compute the MMDF
and Babyl separator bytes once instead of per line.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants