Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-93618: Document the memory usage of the incremental parsers - #156763

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-93618-iterparse-memory-docs
Sep 13, 2026
Merged

gh-93618: Document the memory usage of the incremental parsers#156763
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:gh-93618-iterparse-memory-docs

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 1, 2026

Copy link
Copy Markdown
Member

The documentation said that iterparse() "can be useful when you're reading a large XML document and don't want to hold it wholly in memory", but the tree is only built incrementally, it is not freed incrementally: every parsed element is kept until the whole document is read.

The claim is replaced with an explanation and two examples for common cases: clearing large processed elements, and removing the processed children of an element with many of them. Both are in the "Pull API for non-blocking parsing" section, because this applies to XMLPullParser as well.

They are not universal, they only give an idea; the note ends with the way to avoid the tree entirely, an XMLParser with a custom target.

It was said that iterparse() can be useful for reading a large document
without holding it wholly in memory, but the tree is only built
incrementally, it is not freed incrementally.  Document how to remove the
processed elements, and that a custom target does not build a tree at all.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34331034 | 📁 Comparing f9f3101 against main (faf4e52)

  🔍 Preview build  

1 file changed
± library/xml.etree.elementtree.html

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Sep 13, 2026
@serhiy-storchaka
serhiy-storchaka merged commit e7a3937 into python:main Sep 13, 2026
42 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Sep 13, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@serhiy-storchaka
serhiy-storchaka deleted the gh-93618-iterparse-memory-docs branch September 13, 2026 12:37
@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157419 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 13, 2026
@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157420 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 13, 2026
@bedevere-app

bedevere-app Bot commented Sep 13, 2026

Copy link
Copy Markdown

GH-157421 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 13, 2026
serhiy-storchaka added a commit that referenced this pull request Sep 13, 2026
…GH-156763) (GH-157420)

It was said that iterparse() can be useful for reading a large document
without holding it wholly in memory, but the tree is only built
incrementally, it is not freed incrementally.  Document how to remove the
processed elements, and that a custom target does not build a tree at all.
(cherry picked from commit e7a3937)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit that referenced this pull request Sep 13, 2026
…GH-156763) (GH-157421)

It was said that iterparse() can be useful for reading a large document
without holding it wholly in memory, but the tree is only built
incrementally, it is not freed incrementally.  Document how to remove the
processed elements, and that a custom target does not build a tree at all.
(cherry picked from commit e7a3937)

Co-authored-by: Serhiy Storchaka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant