Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

argparse performance regression in 3.14+ due to colorization overhead #142267

Closed
Assignees
savannahostrowski
Labels
3.14bugs and security fixes3.15new features, bugs and security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@savannahostrowski

Description

@savannahostrowski

I spent some time running theargparsebm_subparsers benchmark frompyperformance (1000 optional arguments, 10 iterations)

VersionTimeFunction Calls
3.100.585s560K
3.110.207s560K
3.120.229s560K
3.130.246s560K
3.140.934s2,380K
3.15 (main)0.883s2,367K

For a "realistic" CLI with 10 arguments, parser creation is ~3x slower on main compared to 3.13.

The root cause is that_get_formatter() is called twice peradd_argument() -once for metavar validation and once in_check_help() for help string validation (called atthe end ofadd_argument ). Each_get_formatter() call creates a newHelpFormatter, which calls_set_color(), which callscan_colorize(), which checks 5 environment variables.

I think a viable fix is to cache theHelpFormatter onArgumentParser for validation operations. The validation only performs read-only operations (_format_args,_expand_help) that don't modify formatter state. This preserves the existing_get_formatter() behavior while eliminating redundant_set_color() calls during argument setup.

Linked PRs

Metadata

Metadata

Labels

3.14bugs and security fixes3.15new features, bugs and security fixesperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp