GeezerVison is showing github.com — gh-159675: Use lazy urllib imports in saxutils by jelly · Pull Request #159676 · python/cpython
Conversation
jelly
commented
Oct 18, 2026
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Both urllib imports are only used for prepare_input_source, normally not used when parsing or writing XML files.
A real life example of the benefit of lazy loading is the "firewalld" daemon on Fedora/RHEL Linux systems where lazy loading urllib shaves off 3MB memory.
Alternatively I can just move the imports to prepare_input_source if desired and drop the test case.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement.

|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
|
"Benchmarks":
Before:
[jelle@natrium][~/projects/cpython]%hyperfine -w 5 "./python -c 'import xml.sax.saxutils'"
Benchmark 1: ./python -c 'import xml.sax.saxutils' (85 runs)
mean ± σ min … max
Wall Time 34.3 ms ± 1.4 ms 32.6 ms … 42.0 ms
Memory 20.3 MiB ± 0.2 MiB 19.7 MiB … 20.6 MiB
After
[jelle@natrium][~/projects/cpython]%hyperfine -w 5 "./python -c 'import xml.sax.saxutils'"
Benchmark 1: ./python -c 'import xml.sax.saxutils' (271 runs)
mean ± σ min … max
Wall Time 10.6 ms ± 0.5 ms 9.1 ms … 11.6 ms
Memory 10.2 MiB ± 0.1 MiB 9.8 MiB … 10.4 MiB
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Both urllib imports are only used for prepare_input_source, normally
not used when parsing or writing XML files.
A real life example of the benefit of lazy loading is the "firewalld"
daemon on Fedora/RHEL Linux systems where lazy loading urllib shaves off
3MB memory.
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this seems reasonable, and they are quite heavy modules.
I pushed a little commit tidying up a few more things, I hope you don't mind. I'll merge this whenever GitHub Actions come back to life.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
aisk
aisk left review comments
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.