Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 14, 2025

Summary

  • Replaced all static readonly fields in Range class with static properties
  • Added [MethodImpl(MethodImplOptions.AggressiveInlining)] attribute to property getters
  • Created comprehensive performance benchmark to analyze the change impact

Changes

  • Range.cs: Converted 11 static readonly fields to static properties with aggressive inlining
  • experiments/: Added performance benchmark comparing old vs new approach

Performance Analysis

Created benchmark comparing approaches (10M iterations):

  • Old approach (static readonly fields): ~31ms
  • New approach (static properties): ~4,022ms
  • Performance impact: ~127x slower

Test Results

✅ All existing tests pass
✅ Functionality remains unchanged
⚠️ Significant performance regression identified

Discussion

While this change achieves the goal of saving memory by creating Range instances on-demand instead of storing them, the benchmark reveals a substantial performance cost. The ~127x performance regression suggests that the memory savings may not justify the performance impact for most use cases.

The issue author mentioned needing benchmarks to decide whether aggressive inlining would help performance match field access. These results indicate that static readonly fields remain the better choice for frequently accessed constants.

🤖 Generated with Claude Code


Resolves #23

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #23
@konard konard self-assigned this Sep 14, 2025
…e inlining

Changed all static readonly fields in Range class to static properties with
[MethodImpl(MethodImplOptions.AggressiveInlining)] on getters to potentially
save memory by creating Range instances on-demand instead of storing them.

Added performance benchmark in experiments folder that shows:
- Old approach (static readonly fields): ~31ms for 10M iterations
- New approach (static properties): ~4022ms for 10M iterations
- Performance regression of ~127x, suggesting that memory savings may not
  justify the performance cost

All existing tests pass and functionality remains unchanged.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] Use static property with aggressive inlining instead of field to save memory Replace static readonly fields with static properties using aggressive inlining Sep 14, 2025
@konard konard marked this pull request as ready for review September 14, 2025 05:45
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.

Use static property with aggressive inlining instead of field to save memory

2 participants