Skip to content

Conversation

@Wulian233
Copy link
Contributor

@Wulian233Wulian233 commented May 30, 2025

importtimeimportosimportposixpathimportLib.posixpathasposixpath_fixedos.environ['A'] ='x'payload="$A"*100000print("Payload size:", len(payload)) start=time.time() posixpath.expandvars(payload) print("Original time:", time.time() -start, "seconds") start=time.time() posixpath_fixed.expandvars(payload) print("Fixed time:", time.time() -start, "seconds")

Above is a code that reproduces the problem, and the speed difference becomes more and more noticeable with the number of times. The above 200,000 times is 15x faster

print:

Payload size: 200000 Original time: 1.7329566478729248 seconds Fixed time: 0.11450839042663574 seconds 

@serhiy-storchaka
Copy link
Member

There is other quadratic complexity here -- in the regular expression. Example: expandvars('${'*1000000).

Also, using re.sub() is more efficient here. See #134952.

@Wulian233
Copy link
ContributorAuthor

Also, using re.sub() is more efficient here. See #134952

#134952 include this fix. What should I do? Should I modify this PR according to your changes or close this PR👀

@serhiy-storchaka
Copy link
Member

I suggest to close this PR in favor of #134952, unless the latter has serious flaws. Thank you anyway.

@Wulian233
Copy link
ContributorAuthor

No problem

@Wulian233Wulian233 deleted the posixpath-dos branch May 31, 2025 07:57
@AA-TurnerAA-Turner removed needs backport to 3.9 needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 14, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Wulian233@serhiy-storchaka@AA-Turner@ZeroIntensity