feat: add object pool pattern#490
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 12 files 12 suites 9m 20s ⏱️ Results for commit b87980e. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
There was a problem hiding this comment.
Pull request overview
Adds a new Object Pool pattern to PatternKit, including a runtime/fluent API in PatternKit.Core, a Roslyn source generator + diagnostics, documentation updates, and an importable DI-backed example with benchmark coverage.
Changes:
- Introduce
ObjectPool<T>with lease-based rent/return semantics and a fluent builder. - Add
GenerateObjectPoolattribute +ObjectPoolGeneratorwith diagnostics and generator tests. - Add spreadsheet-formula demo (fluent + generated routes), DI integration, docs/catalog/README updates, and BenchmarkDotNet coverage.
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Creational/ObjectPool/ObjectPoolTests.cs | Adds TinyBDD runtime coverage for pool reset/retention/disposal/builder validation. |
| test/PatternKit.Generators.Tests/ObjectPoolGeneratorTests.cs | Adds generator output + diagnostic scenario tests for ObjectPoolGenerator. |
| test/PatternKit.Generators.Tests/AbstractionsTests.cs | Adds attribute-level tests for GenerateObjectPoolAttribute. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates canonical pattern list to include Object Pool. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs | Updates published benchmark route-result totals to include Object Pool. |
| test/PatternKit.Examples.Tests/ObjectPoolDemo/SpreadsheetFormulaObjectPoolDemoTests.cs | Adds example verification for fluent vs generated pool consistency and DI importability. |
| src/PatternKit.Generators/ObjectPool/ObjectPoolGenerator.cs | Implements the incremental generator and diagnostics for object pool factories. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Documents new generator diagnostic IDs (PKOP001–PKOP003). |
| src/PatternKit.Generators.Abstractions/ObjectPool/ObjectPoolAttributes.cs | Adds GenerateObjectPoolAttribute to the abstractions package. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds Object Pool to the production-readiness catalog with doc/source/test links. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Registers the new spreadsheet formula object pool example in the example catalog. |
| src/PatternKit.Examples/ObjectPoolDemo/SpreadsheetFormulaObjectPoolDemo.cs | Adds the DI-backed spreadsheet formula demo using fluent + generated pools. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the new demo into AddPatternKitExamples registrations. |
| src/PatternKit.Core/Creational/ObjectPool/ObjectPool.cs | Adds the runtime ObjectPool<T> + ObjectPoolLease<T> implementation. |
| README.md | Updates pattern counts/table and adds pending benchmark rows for Object Pool. |
| docs/patterns/toc.yml | Adds Object Pool to patterns TOC. |
| docs/patterns/index.md | Adds Object Pool to patterns landing page list. |
| docs/patterns/creational/object-pool/index.md | Adds Object Pool pattern documentation and usage examples. |
| docs/guides/pattern-coverage.md | Updates coverage guide matrix to include Object Pool. |
| docs/guides/benchmarks.md | Adds Object Pool “Pending” rows to benchmark guide table. |
| docs/guides/benchmark-results.md | Updates benchmark results matrices/totals and adds Object Pool rows + generator listing. |
| docs/generators/toc.yml | Adds Object Pool generator doc entry to generator TOC. |
| docs/generators/object-pool.md | Adds generator documentation for GenerateObjectPoolAttribute + diagnostics. |
| docs/generators/index.md | Adds Object Pool to generator index table. |
| docs/examples/toc.yml | Adds the spreadsheet formula object pool example to examples TOC. |
| docs/examples/spreadsheet-formula-object-pool.md | Adds documentation for the new spreadsheet demo. |
| benchmarks/PatternKit.Benchmarks/Creational/ObjectPoolBenchmarks.cs | Adds BenchmarkDotNet routes for construction/execution (fluent vs generated). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| internal void Return(T value) | ||
| { | ||
| if (_disposed) | ||
| { | ||
| DisposeIfNeeded(value); | ||
| return; | ||
| } | ||
|
|
||
| _onReturn?.Invoke(value); | ||
| if (_shouldReturn is not null && !_shouldReturn(value)) | ||
| { | ||
| DisposeIfNeeded(value); | ||
| return; | ||
| } | ||
|
|
||
| var retained = Interlocked.Increment(ref _retained); | ||
| if (retained <= _maxRetained) | ||
| { | ||
| _items.Enqueue(value); | ||
| return; | ||
| } | ||
|
|
||
| Interlocked.Decrement(ref _retained); | ||
| DisposeIfNeeded(value); | ||
| } |
| public void Dispose() | ||
| { | ||
| _disposed = true; | ||
| while (_items.TryDequeue(out var value)) | ||
| { | ||
| Interlocked.Decrement(ref _retained); | ||
| DisposeIfNeeded(value); | ||
| } | ||
| } |
Adds a bounded fluent ObjectPool<T> with lease-based rent/return semantics, a source-generated factory path, DI-backed spreadsheet example, docs, catalog entries, benchmark coverage, and TinyBDD tests.\n\nFixes #486
79485d3 to
b87980e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #490 +/- ##
==========================================
+ Coverage 97.42% 97.49% +0.07%
==========================================
Files 579 583 +4
Lines 47161 47419 +258
Branches 3067 6809 +3742
==========================================
+ Hits 45947 46232 +285
+ Misses 1214 1187 -27
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Code Coverage |
Summary\n- add bounded fluent ObjectPool with lease-based rent/return semantics\n- add GenerateObjectPool source generator, diagnostics, docs, and TinyBDD coverage\n- add DI-backed spreadsheet formula example, benchmark coverage, and catalog/README updates\n\nFixes #486\n\n## Validation\n- dotnet test test\PatternKit.Tests\PatternKit.Tests.csproj --framework net8.0 --no-restore\n- dotnet test test\PatternKit.Generators.Tests\PatternKit.Generators.Tests.csproj --framework net8.0 --no-restore\n- dotnet test test\PatternKit.Examples.Tests\PatternKit.Examples.Tests.csproj --framework net8.0 --no-restore\n- dotnet build benchmarks\PatternKit.Benchmarks\PatternKit.Benchmarks.csproj --framework net8.0 --no-restore\n- dotnet build PatternKit.slnx --no-restore