Skip to content

Conversation

@AA-Turner
Copy link
Member

@AA-TurnerAA-Turner commented Apr 2, 2025

This PR achieves a 33x improvement in import time for the shlex module and a 4-12x improvement in performance for shlex.quote.

Current:

import shlex: cumulative time mean: 9065.967 µs median: 9092.000 µs stdev: 282.015 min: 8587 max: 9556 

This PR:

import shlex: cumulative time mean: 274.300 µs median: 275.000 µs stdev: 8.860 min: 259 max: 289 

@AA-TurnerAA-Turner added the performance Performance or resource usage label Apr 2, 2025
@JelleZijlstra
Copy link
Member

I'm not sure this is practically useful, since pretty much anything you'd do within the module will trigger the imports. Also, importing sys and io is practically free since they're imported at startup.

@AA-Turner
Copy link
MemberAuthor

AA-Turner commented Apr 4, 2025

True, this one is more marginal. quote and join will only import re, whereas split and shlex will import collections/os.path. Where shlex is used in the stdlib, it's often only one of these two groups, so I think it could still have benefits?

Edit: quote and join now no longer import re

A

@python-cla-bot

This comment was marked as resolved.

@AA-TurnerAA-Turner requested a review from picnixzApril 20, 2025 21:50
@AA-TurnerAA-Turner merged commit 06a26fd into python:mainApr 24, 2025
39 checks passed
@AA-TurnerAA-Turner deleted the opt-shlex branch April 24, 2025 15:10
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performancePerformance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@AA-Turner@JelleZijlstra@picnixz@rruuaanng