Skip to content

Commit 3dfd79a

Browse files
committed
feat: adicionar suporte a constantes públicas para configuração e testes no JsonBufferPool
1 parent 2e8d02c commit 3dfd79a

File tree

8 files changed

+811
-16
lines changed

8 files changed

+811
-16
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- **Automatic Integration**: `Response::json()` now uses pooling transparently for optimal performance
1717
- **Smart Detection**: Automatically activates pooling for arrays 10+ elements, objects 5+ properties, strings >1KB
1818
- **Graceful Fallback**: Small datasets use traditional `json_encode()` for best performance
19+
- **Public Constants**: All size estimation and threshold constants are now publicly accessible for advanced usage and testing
1920

2021
- **Performance Monitoring & Statistics**:
2122
- Real-time pool statistics with reuse rates and efficiency metrics
@@ -28,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2829
- **Transparent Optimization**: Automatic activation based on data characteristics
2930
- **Manual Control**: Direct pool access via `JsonBufferPool::encodeWithPool()` when needed
3031
- **Configuration API**: Production tuning via `JsonBufferPool::configure()`
32+
- **Enhanced Error Handling**: Precise validation messages separating type vs range errors
33+
- **Type Safety**: `encodeWithPool()` now always returns string, simplifying error handling
3134

3235
#### Performance Improvements
3336
- **Sustained Throughput**: 101,000+ JSON operations per second in continuous load tests
@@ -37,9 +40,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3740

3841
#### Technical Details
3942
- **PSR-12 Compliant**: All new code follows project coding standards
40-
- **Comprehensive Testing**: 20 new tests with 60 assertions covering all functionality
43+
- **Comprehensive Testing**: 84 JSON tests with 329+ assertions covering all functionality
4144
- **Backward Compatible**: No changes required to existing applications
4245
- **Production Ready**: Tested with various data sizes and load patterns
46+
- **Centralized Constants**: All thresholds and size constants are unified to avoid duplication
47+
- **Test Maintainability**: Tests now use constants instead of hardcoded values for better maintainability
4348

4449
#### Files Added
4550
- `src/Json/Pool/JsonBuffer.php`: Core buffer implementation
@@ -52,6 +57,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5257
- `src/Http/Response.php`: Integrated automatic pooling in `json()` method
5358
- Enhanced with smart detection and fallback mechanisms
5459

60+
#### Post-Release Improvements (July 2025)
61+
- **Enhanced Configuration Validation**: Separated type checking from range validation for more precise error messages
62+
- **Improved Type Safety**: `encodeWithPool()` method now has tightened return type (always returns string)
63+
- **Public Constants Exposure**: Made all size estimation and threshold constants public for advanced usage and testing
64+
- **Centralized Thresholds**: Unified pooling decision thresholds across Response.php and JsonBufferPool to eliminate duplication
65+
- **Test Maintainability**: Updated all tests to use constants instead of hardcoded values
66+
- **Documentation Updates**:
67+
- Added comprehensive [Constants Reference Guide](docs/technical/json/CONSTANTS_REFERENCE.md)
68+
- Updated performance guide with recent improvements
69+
- Enhanced error handling documentation
70+
5571
## [1.1.0] - 2025-07-09
5672

5773
### 🚀 **High-Performance Edition**

docs/releases/v1.1.1/RELEASE_NOTES.md

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,43 @@ $response->json($data); // Now uses pooling when beneficial
2828
```
2929

3030
**Smart Detection Criteria:**
31-
- Arrays with 10+ elements
32-
- Objects with 5+ properties
33-
- Strings larger than 1KB
31+
- Arrays with 10+ elements (JsonBufferPool::POOLING_ARRAY_THRESHOLD)
32+
- Objects with 5+ properties (JsonBufferPool::POOLING_OBJECT_THRESHOLD)
33+
- Strings larger than 1KB (JsonBufferPool::POOLING_STRING_THRESHOLD)
3434

35-
### Manual Pool Control
35+
### Enhanced Error Handling & Type Safety
36+
37+
**Precise Validation Messages:**
38+
```php
39+
// Type errors are clearly separated from range errors
40+
try {
41+
JsonBufferPool::configure(['max_pool_size' => 'invalid']);
42+
} catch (InvalidArgumentException $e) {
43+
echo $e->getMessage(); // "'max_pool_size' must be an integer"
44+
}
45+
46+
try {
47+
JsonBufferPool::configure(['max_pool_size' => -1]);
48+
} catch (InvalidArgumentException $e) {
49+
echo $e->getMessage(); // "'max_pool_size' must be a positive integer"
50+
}
51+
```
52+
53+
**Always-String Return Type:**
54+
```php
55+
// encodeWithPool() now always returns string, never false
56+
$json = JsonBufferPool::encodeWithPool($data); // Always string
57+
// No need to check for false - error handling is internal
58+
```
59+
60+
### Manual Pool Control & Public Constants
3661

3762
For advanced use cases, direct pool access is available:
3863

3964
```php
4065
use PivotPHP\Core\Json\Pool\JsonBufferPool;
4166

42-
// Direct encoding with pooling
67+
// Direct encoding with pooling (always returns string)
4368
$json = JsonBufferPool::encodeWithPool($data);
4469

4570
// Manual buffer management
@@ -49,6 +74,27 @@ $result = $buffer->finalize();
4974
JsonBufferPool::returnBuffer($buffer);
5075
```
5176

77+
**Public Constants for Advanced Usage:**
78+
```php
79+
// Size estimation constants
80+
JsonBufferPool::EMPTY_ARRAY_SIZE; // 2
81+
JsonBufferPool::SMALL_ARRAY_SIZE; // 512
82+
JsonBufferPool::MEDIUM_ARRAY_SIZE; // 2048
83+
JsonBufferPool::LARGE_ARRAY_SIZE; // 8192
84+
JsonBufferPool::XLARGE_ARRAY_SIZE; // 32768
85+
86+
// Pooling thresholds
87+
JsonBufferPool::POOLING_ARRAY_THRESHOLD; // 10
88+
JsonBufferPool::POOLING_OBJECT_THRESHOLD; // 5
89+
JsonBufferPool::POOLING_STRING_THRESHOLD; // 1024
90+
91+
// Type-specific constants
92+
JsonBufferPool::STRING_OVERHEAD; // 20
93+
JsonBufferPool::OBJECT_PROPERTY_OVERHEAD; // 50
94+
JsonBufferPool::OBJECT_BASE_SIZE; // 100
95+
JsonBufferPool::MIN_LARGE_BUFFER_SIZE; // 65536
96+
```
97+
5298
### Real-time Monitoring
5399

54100
Comprehensive statistics for production monitoring:
@@ -180,17 +226,20 @@ For maximum performance, consider these enhancements:
180226

181227
### Test Coverage
182228

183-
- **20 new tests** covering all JSON pooling functionality
184-
- **60 additional assertions** validating behavior
229+
- **84 JSON tests** covering all pooling functionality
230+
- **329+ total assertions** validating behavior
185231
- **All existing tests** continue to pass (335+ tests total)
186232
- **PSR-12 compliance** maintained throughout
233+
- **Enhanced test maintainability** with constant-based assertions
187234

188235
### Validation
189236

190237
- **Memory leak testing** - No buffer leaks detected
191238
- **Stress testing** - 60+ seconds sustained load
192239
- **Compatibility testing** - All existing functionality preserved
193240
- **Performance regression testing** - No slowdowns for any use case
241+
- **Type safety validation** - Precise error message testing
242+
- **Configuration validation** - Comprehensive parameter checking
194243

195244
## 🎯 Use Cases
196245

0 commit comments

Comments
 (0)