# Improving dataclasses startup performance

**URL:** <https://discuss.python.org/t/improving-dataclasses-startup-performance/15442>\
**Category:** Committers\
**Created:** [May 2, 2022, 11:16pm UTC](https://discuss.python.org/t/improving-dataclasses-startup-performance/15442 "2022-05-02T23:16:56Z")\
**Posts on this page:** 1\
**Showing post:** 20

<div class="post-metadata">

**Author:** ![brandtbucher](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/brandtbucher/32/22862_2.png) [@brandtbucher](https://discuss.python.org/u/brandtbucher)\
**Post date:** [May 10, 2022, 3:11pm UTC](https://discuss.python.org/t/improving-dataclasses-startup-performance/15442/20 "2022-05-10T15:11:58Z")

</div>

I decided to take a look at this yesterday.

I’ve gotten a very rough version of code-caching working for `dataclasses` (all tests are passing). As a preliminary benchmark, the `dataclasses` test suite is running about twice as quickly… I haven’t timed `@dataclass` generation time specifically yet, but I suspect that it’s even better than that (the tests are doing a lot more than just generating dataclasses, and the generated code hasn’t changed at all).

Something like 95% of generated methods don’t actually go through `exec`, but just use `code.replace` to patch a few names and constants. I also expect that memory use has improved as well. I’ll be doing more cleanup and experiments on my branch today.

---

_[View the full topic](https://discuss.python.org/t/improving-dataclasses-startup-performance/15442)._
