GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159675: Use lazy urllib imports in saxutils by jelly · Pull Request #159676 · python/cpython

Conversation

@jelly

@jelly jelly commented Oct 18, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

  • Issue: Lazy load urllib modules in saxutils #159675

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@python-cla-bot

python-cla-bot Bot commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 18, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Oct 18, 2026
Lazy load urllib modules in saxutils #159675
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Oct 18, 2026
@bedevere-app

This comment was marked as resolved.

Sign in to view
@jelly

jelly commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

"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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aisk
aisk reviewed Oct 18, 2026
View reviewed changes
Comment thread Lib/test/test_sax.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_sax.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jelly
Use lazy urllib imports in saxutils
66c3450
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.
@jelly
jelly force-pushed the saxutils-lazy-load-urllib branch from c7f16ed to 66c3450 Compare October 18, 2026 18:07
@bedevere-app

This comment was marked as resolved.

Sign in to view
@StanFromIreland
Tidy up a few more imports
b961b18
@bedevere-app

This comment was marked as resolved.

Sign in to view
@StanFromIreland StanFromIreland added the skip news label Oct 19, 2026
StanFromIreland
StanFromIreland approved these changes Oct 19, 2026
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

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.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Oct 19, 2026
@StanFromIreland
StanFromIreland merged commit 2dd5315 into python:main Oct 19, 2026
57 of 59 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 19, 2026
@StanFromIreland

StanFromIreland commented Oct 19, 2026

Copy link
Copy Markdown
Member

Merged, thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aisk aisk aisk left review comments
@StanFromIreland StanFromIreland StanFromIreland approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news type-feature A feature request or enhancement

Projects

None yet

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.

3 participants

@jelly @StanFromIreland @aisk
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.