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.
Constructing a
ConfigParserscans every attribute on the parser withdir()and matches each name against a regular expression to discover itsget<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.cfgend to end improves by 19%. The discovered converters are identical to those found today.