Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

Comprehensive analysis comparing Platform.Collections.ArrayPool with .NET's ConfigurableArrayPool addressing performance, memory leaks, and thread safety as requested in issue #101.

Key Findings

Performance Comparison

  • Single-threaded: Platform.Collections.ArrayPool is faster (zero synchronization overhead)
  • Multi-threaded: ConfigurableArrayPool may perform better (shared resource utilization)
  • High contention: Platform.Collections.ArrayPool avoids lock contention entirely

Memory Leak Analysis

  • Platform.Collections.ArrayPool: Higher risk due to thread-static isolation
  • ConfigurableArrayPool: Lower risk with centralized management and monitoring
  • Both: Handle pool overflow by discarding arrays (no infinite growth)

Thread Safety

  • Platform.Collections.ArrayPool: Thread-safe via per-thread isolation (ThreadStatic)
  • ConfigurableArrayPool: Thread-safe via SpinLock with resource sharing
  • Both: Verified safe under high concurrency (20 threads, 10k+ operations)

Implementation

Added Files

  • ConfigurableArrayPool.cs - Simplified .NET ConfigurableArrayPool implementation
  • ArrayPoolBenchmarks.cs - Performance comparison benchmarks
  • ArrayPoolThreadSafetyTests.cs - Comprehensive thread safety tests
  • experiments/ArrayPool_Comparison_Report.md - Detailed analysis report

Test Results

✅ All thread safety tests pass
✅ Memory leak tests show acceptable growth
✅ Concurrent access stress tests (20 threads × 500 operations) pass

Recommendations

Choose Platform.Collections.ArrayPool for:

  • High-performance single-threaded scenarios
  • Applications requiring zero synchronization overhead
  • Simple, predictable per-thread behavior

Choose ConfigurableArrayPool for:

  • Multi-threaded applications with resource constraints
  • Applications requiring centralized pool monitoring
  • Scenarios where cross-thread resource sharing is beneficial

How to Run

# Run benchmarks
cd csharp
dotnet run --project Platform.Collections.Benchmarks -c Release

# Run thread safety tests
dotnet test Platform.Collections.Tests --filter "ArrayPoolThreadSafetyTests"

Fixes #101

🤖 Generated with Claude Code

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

Issue: #101
@konard konard self-assigned this Sep 13, 2025
- Implement ConfigurableArrayPool based on .NET design for comparison
- Add performance benchmarks comparing Platform.Collections.ArrayPool vs ConfigurableArrayPool vs .NET ArrayPool.Shared
- Add comprehensive thread safety tests with concurrent access validation
- Analyze memory leak possibilities in both implementations
- Document findings: Platform.Collections.ArrayPool better for single-threaded, ConfigurableArrayPool better for multi-threaded scenarios
- Make ArrayPool.ThreadInstance public for testing access
- Create detailed comparison report with recommendations

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

Co-Authored-By: Claude <[email protected]>
@konard konard changed the title [WIP] Compare ArrayPool and ConfigurableArrayPool from .NET 5 Compare ArrayPool and ConfigurableArrayPool from .NET 5 - Complete Analysis Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 17:38
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.

Compare ArrayPool and ConfigurableArrayPool from .NET 5

2 participants