Release Date: 2025-12-16
Version 0.8.0 is a major performance-focused release that delivers significant speed improvements across all collection types while maintaining 100% backward compatibility. This release focuses on optimizing the underlying data structures and algorithms without changing any public APIs.
- TThreadSafeDeque: 5-10x faster with new circular array implementation
- TThreadSafeList: 2-3x faster bulk operations with smart pre-allocation
- TThreadSafeDictionary & TThreadSafeHashSet: 1.5-2x faster bulk operations
- Memory efficiency: Up to 100x fewer allocations for deque operations
- Cache locality: Dramatically improved with contiguous memory layout
-
Deque Architecture Rewrite (Breaking Performance Improvement)
- Converted from linked-list to circular array-based implementation
- Eliminated per-item heap allocations (New/Dispose calls removed)
- Power-of-2 capacity sizing for efficient modulo operations
- 100% API compatible - no code changes required
-
List Pre-allocation Strategy
- New optional constructor:
Create(AComparer, AInitialCapacity) - Default initial capacity increased from 0 to 16 elements
- Smart growth: 2x for small lists, 1.5x for large lists
- Optimized
AddRangewith single pre-calculated resize
- New optional constructor:
-
Hash Table Bulk Optimization
AddRangemethods now pre-calculate required capacity- Single resize operation instead of multiple cascading resizes
- Reduced lock contention during bulk operations
| Operation | Pre-v0.8 | v0.8 | Improvement |
|---|---|---|---|
| Deque: Push/Pop | O(1) with heap allocation | O(1) stack-based | ~5-10x faster |
| Deque: 1000 items | ~1000 allocations | ~10 allocations | ~100x fewer allocations |
| List: AddRange(1000) | ~10 resizes | ~1 resize | ~10x fewer resizes |
| List: Memory growth | 100% (doubles) | 50% (large lists) | ~33% less memory waste |
| HashSet: AddRange(1000) | Multiple resizes | Single resize | ~2-5x faster |
| Memory fragmentation | High (linked-list) | Low (array-based) | Significantly improved |
From test suite execution (116 tests):
- List sorting (100k items): ~200-350ms
- Hash operations (10k items): <10ms for add/contains
- Concurrent access: Maintains thread safety with minimal overhead
- Deque operations: Now O(1) push/pop with better constant factors
- Deque: Eliminated heap allocations for individual nodes, reducing memory fragmentation
- List: Smarter capacity growth reduces wasted allocations
- Hash Tables: Pre-calculation prevents intermediate resize operations
- Deque: Circular array with bitwise AND for wraparound (efficient modulo)
- List: Geometric growth with size-dependent strategy
- Hash Tables: Bulk operation optimization with single resize
TThreadSafeList:
// Before (still works):
List := specialize TThreadSafeList<Integer>.Create(@IntegerComparer);
// After (optional optimization):
List := specialize TThreadSafeList<Integer>.Create(@IntegerComparer, 1000);TThreadSafeDeque:
// Before (still works):
Deque := specialize TThreadSafeDeque<Integer>.Create;
// After (optional optimization):
Deque := specialize TThreadSafeDeque<Integer>.Create(1000);- List initial capacity: Changed from 0 to 16 (performance optimization)
- Deque initial capacity: Changed from 0 to 16 (performance optimization)
All existing code continues to work without modifications.
100% backward compatible - All existing code will work without any changes.
- All public APIs remain unchanged
- All method signatures preserved
- All behaviors maintained (except performance improvements)
- Existing constructors still work as before
- New constructors are optional enhancements
All optimizations verified with comprehensive test suite:
- ✅ 116 tests passing
- ✅ Thread safety verified with concurrent access tests
- ✅ Memory management tested with stress tests
- ✅ Hash collision handling verified
- ✅ Bulk operations tested with large datasets
- ✅ Iterator functionality confirmed
- ✅ Edge cases covered (empty collections, single items, etc.)
The following optimizations were considered but deferred to future releases:
-
Read-write locks (
TMultiReadExclusiveWriteSynchronizer)- Would allow concurrent reads
- Requires extensive refactoring
- Planned for future release
-
Lock-free atomic operations
- For simple checks (IsEmpty, Count)
- Requires significant architecture changes
- Planned for future release
No installation changes - same as previous versions:
- Clone or download the repository
- Add
srcdirectory to your project's search path - Add units to your uses clause as needed
- Repository: https://github.com/ikelaiah/threadsafecollections-fp
- Documentation: See README.md
- Full Changelog: See CHANGELOG.md
- Issues: https://github.com/ikelaiah/threadsafecollections-fp/issues
- Free Pascal and Lazarus community
- FPCUnit testing framework
- All contributors and testers
This library is primarily a learning tool. For production applications, consider:
Simply replace your existing source files. No code changes required.
If you want to take advantage of the new performance optimizations:
- Use the new constructors with capacity hints when you know approximate collection sizes
- Recompile your application to pick up the performance improvements
What's Next?
Future releases will focus on:
- Read-write lock support for concurrent reads
- Lock-free operations for performance-critical paths
- Additional specialized collection types
- More comprehensive benchmarking suite
Thank you for using ThreadSafeCollections-FP!