best-practices
Class Design for Compilation
Design classes and methods that compile efficiently.
Published May 30, 2026
Simple Classes Compile Best
@dataclass
class Point:
x: float
y: floatAvoid Complex Metaclasses
Custom metaclasses other than ABCMeta may fall back to CPython.
Prefer Slots for Memory
class Item:
__slots__ = ['name', 'price']Method Call Overhead
Method calls are slightly slower than free functions. For hot inner loops, consider extracting to a free function.