Improving dataclasses startup performance

Here’s my prototype. Reviews welcome:

Implement dataclass code caching by brandtbucher · Pull Request #92650 · python/cpython (github.com)

6 Likes

I’ve tried this out on a microlevel for attrs (going all-in requires significant refactorings) and got speed improvements of 19 us between compiling the default methods one by one vs all one once. That’s approximately a 10% speedup: bench_eval.py · GitHub

However the whole class takes 461 us so the 19 us are only ~4%. Might still be worth it, depending on the amount of complexity the refactoring would cause.

2 Likes