Commit 9efcc45
committed
Add __slots__ to metadata classes for memory optimization
Implemented __slots__ for ColumnMetadata and IndexMetadata classes
in cassandra/metadata.py to reduce per-instance memory overhead.
Changes:
- ColumnMetadata: Added __slots__ with 6 attributes (table, name,
cql_type, is_static, is_reversed, _cass_type)
- IndexMetadata: Added __slots__ with 5 attributes (keyspace_name,
table_name, name, kind, index_options)
- Removed class-level attribute definitions that conflicted with
__slots__ declarations
- All attribute initialization moved to __init__ methods
- Preserved attribute documentation in class docstrings
Memory Impact:
Each instance saves approximately 280-300 bytes by eliminating the
per-instance __dict__. These metadata objects are created frequently
when parsing schema information, making this optimization valuable
for clusters with many tables and indexes.
Testing:
- All 648 unit tests pass successfully
- Metadata-specific tests: 53 passed, 2 skipped
- No functionality changes or regressions
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent d062ec2 commit 9efcc45
1 file changed
Lines changed: 18 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1647 | 1647 | | |
1648 | 1648 | | |
1649 | 1649 | | |
1650 | | - | |
1651 | | - | |
1652 | | - | |
1653 | | - | |
1654 | | - | |
1655 | | - | |
1656 | | - | |
1657 | | - | |
1658 | | - | |
1659 | | - | |
1660 | | - | |
1661 | | - | |
1662 | | - | |
1663 | | - | |
1664 | | - | |
1665 | | - | |
1666 | | - | |
1667 | | - | |
1668 | 1650 | | |
1669 | | - | |
1670 | | - | |
1671 | | - | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
1672 | 1659 | | |
1673 | 1660 | | |
1674 | | - | |
| 1661 | + | |
1675 | 1662 | | |
1676 | 1663 | | |
1677 | 1664 | | |
1678 | 1665 | | |
1679 | 1666 | | |
1680 | 1667 | | |
1681 | 1668 | | |
| 1669 | + | |
1682 | 1670 | | |
1683 | 1671 | | |
1684 | 1672 | | |
| |||
1687 | 1675 | | |
1688 | 1676 | | |
1689 | 1677 | | |
1690 | | - | |
1691 | | - | |
1692 | | - | |
1693 | 1678 | | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
1702 | 1686 | | |
1703 | | - | |
1704 | | - | |
| 1687 | + | |
1705 | 1688 | | |
1706 | 1689 | | |
1707 | 1690 | | |
| |||
0 commit comments