Skip to content

gh-159675: Use lazy urllib imports in saxutils - #159676

Open
jelly wants to merge 1 commit into
python:mainfrom
jelly:saxutils-lazy-load-urllib
Open

jelly wants to merge 1 commit into
python:mainfrom
jelly:saxutils-lazy-load-urllib

Conversation

@jelly

@jelly jelly commented Oct 18, 2026 •

Copy link
Copy Markdown

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.

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.
@python-cla-bot

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 18, 2026
@bedevere-app

bedevere-app Bot commented Oct 18, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@jelly

jelly commented Oct 18, 2026

Copy link
Copy Markdown
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

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

Labels

awaiting review type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant