Skip to content

Conversation

@ESultanik
Copy link
Collaborator

Summary

  • Add caching for bounds() method in AbstractEdit
  • Reduces redundant Range object creation

Changes

Profiling showed bounds() was called 230k+ times for a 200-element list diff, often returning the same values. This adds a simple cache:

  • Add _cached_bounds attribute initialized to None
  • Return cached value if available in bounds()
  • Add invalidate_bounds_cache() method for cache invalidation

Note: Subclasses that override bounds() (like PossibleEdits, EditCollection) manage their own caching. This primarily benefits ConstantCostEdit subclasses and calls to super().bounds().

Test plan

  • All 66 tests pass

🤖 Generated with Claude Code

Add caching for bounds() method in AbstractEdit to reduce redundant
Range object creation. Profiling showed bounds() was called 230k+
times for a 200-element list diff, often returning the same values.

Changes:
- Add _cached_bounds attribute initialized to None
- Return cached value if available
- Add invalidate_bounds_cache() method for cache invalidation

Note: Subclasses that override bounds() (like PossibleEdits,
EditCollection) manage their own caching. This primarily benefits
ConstantCostEdit subclasses and calls to super().bounds().

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