Skip to content

Speed up ConfigParser construction by caching converter names #150819

@gaborbernat

Description

@gaborbernat

Constructing a ConfigParser scans every attribute on the parser with dir() and matches each name against a regular expression to discover its get<type> converter methods. That discovery produces the same answer for every instance of a given parser class, yet it runs in full on each construction.

Tools that read several config files, or construct a fresh parser per file, pay this cost repeatedly. Build backends, linters and test runners commonly create many parsers over a run.

Constructing a parser takes 390 µs today and 78.9 µs when the converter names are discovered once per class and reused, 394% faster for construction; constructing and reading a real setup.cfg end to end improves by 19%. The discovered converters are identical to those found today.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions