]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-116159: argparse: performance improvement parsing large number of options (#116162)
authorAmethyst Reese <amethyst@n7.gg>
Fri, 1 Mar 2024 10:52:53 +0000 (02:52 -0800)
committerGitHub <noreply@github.com>
Fri, 1 Mar 2024 10:52:53 +0000 (11:52 +0100)
commit4a630980328b67f0aba6a04c3950aa9dbd532895
tree5dcd78b09e4967f71482ecdd4de9ed50eaa21038
parent7b4794319c56b6b00e852c745af50fd95bd1a550
gh-116159: argparse: performance improvement parsing large number of options (#116162)

When parsing positional vs optional arguments, the use of min with a
list comprehension inside of a loop results in quadratic time based
on the number of optional arguments given. When combined with use of
prefix based argument files and a large number of optional flags, this
can result in extremely slow parsing behavior.

This replaces the min call with a simple loop with a short circuit to
break at the next optional argument.

Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
Lib/argparse.py