Skip to content

Conversation

@ESultanik
Copy link
Collaborator

Summary

  • Add __slots__ to frequently instantiated classes
  • Reduces memory overhead (Range: 344 bytes → 48 bytes per object)
  • Improves attribute access speed

Changes

  • bounds.py: Infinity, Range, ConstantBound, BoundedComparator
  • edits.py: AbstractEdit and all subclasses (Match, Replace, Insert, Remove, etc.)
  • graphtage.py: KeyValuePairEdit, FixedKeyDictNodeEdit, StringEdit
  • levenshtein.py: EditDistance
  • multiset.py: MultiSetEdit
  • sequences.py: SequenceEdit, FixedLengthSequenceEdit

Benchmark

Range objects are created 230k+ times per 200-element list diff. Each Range without __slots__ has a 296-byte __dict__ overhead. With __slots__, total object size is 48 bytes - an 86% memory reduction per object.

Test plan

  • All 66 tests pass

🤖 Generated with Claude Code

Add __slots__ declarations to frequently instantiated classes to reduce
memory overhead and improve attribute access speed:

- bounds.py: Infinity, Range, ConstantBound, BoundedComparator
- edits.py: AbstractEdit and all subclasses (Match, Replace, etc.)
- graphtage.py: KeyValuePairEdit, FixedKeyDictNodeEdit, StringEdit
- levenshtein.py: EditDistance
- multiset.py: MultiSetEdit
- sequences.py: SequenceEdit, FixedLengthSequenceEdit

Range objects are created 230k+ times per diff. Without __slots__,
each has a 296-byte __dict__ overhead. With __slots__, total object
size is 48 bytes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants