Thanks! How would that change affect performance?
https://github.com/jcrist/msgspec/blob/main/benchmarks/bench_structs.py
main:
+----------------------+-------------+-------------+---------------+------------+
| | import (μs) | create (μs) | equality (μs) | order (μs) |
+======================+=============+=============+===============+============+
| **msgspec** | 12.82 | 0.10 | 0.02 | 0.03 |
+----------------------+-------------+-------------+---------------+------------+
| **standard classes** | 9.68 | 0.43 | 0.07 | 0.21 |
+----------------------+-------------+-------------+---------------+------------+
| **attrs** | 466.53 | 0.43 | 0.07 | 2.10 |
+----------------------+-------------+-------------+---------------+------------+
| **dataclasses** | 606.02 | 0.44 | 0.19 | 0.21 |
+----------------------+-------------+-------------+---------------+------------+
| **pydantic** | 320.21 | 1.84 | 1.01 | N/A |
+----------------------+-------------+-------------+---------------+------------+
this pr:
+----------------------+-------------+-------------+---------------+------------+
| | import (μs) | create (μs) | equality (μs) | order (μs) |
+======================+=============+=============+===============+============+
| **msgspec** | 13.75 | 0.11 | 0.02 | 0.03 |
+----------------------+-------------+-------------+---------------+------------+
| **standard classes** | 10.17 | 0.46 | 0.08 | 0.22 |
+----------------------+-------------+-------------+---------------+------------+
| **attrs** | 497.77 | 0.48 | 0.07 | 2.24 |
+----------------------+-------------+-------------+---------------+------------+
| **dataclasses** | 651.33 | 0.48 | 0.20 | 0.21 |
+----------------------+-------------+-------------+---------------+------------+
| **pydantic** | 340.21 | 1.86 | 1.08 | N/A |
+----------------------+-------------+-------------+---------------+------------+
https://github.com/jcrist/msgspec/blob/main/benchmarks/bench_gc.py
main:
+-----------------------------------+--------------+-------------------+
| | GC time (ms) | Memory Used (MiB) |
+===================================+==============+===================+
| **standard class** | 133.60 | 204.03 |
+-----------------------------------+--------------+-------------------+
| **standard class with __slots__** | 96.68 | 120.11 |
+-----------------------------------+--------------+-------------------+
| **msgspec struct** | 24.18 | 120.11 |
+-----------------------------------+--------------+-------------------+
| **msgspec struct with gc=False** | 2.38 | 104.85 |
+-----------------------------------+--------------+-------------------+
this pr:
+-----------------------------------+--------------+-------------------+
| | GC time (ms) | Memory Used (MiB) |
+===================================+==============+===================+
| **standard class** | 132.79 | 204.03 |
+-----------------------------------+--------------+-------------------+
| **standard class with __slots__** | 97.56 | 120.11 |
+-----------------------------------+--------------+-------------------+
| **msgspec struct** | 23.94 | 120.11 |
+-----------------------------------+--------------+-------------------+
| **msgspec struct with gc=False** | 2.39 | 104.85 |
+-----------------------------------+--------------+-------------------+
python -VV
Python 3.12.11 (main, Jun 4 2025, 08:56:18) [GCC 9.4.0]