Skip to content

feat: add object pool pattern#490

Merged
JerrettDavis merged 1 commit into
mainfrom
patterns/object-pool-486
May 31, 2026
Merged

feat: add object pool pattern#490
JerrettDavis merged 1 commit into
mainfrom
patterns/object-pool-486

Conversation

@JerrettDavis

Copy link
Copy Markdown
Owner

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

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Test Results

    12 files      12 suites   9m 20s ⏱️
 4 056 tests  4 056 ✅ 0 💤 0 ❌
12 599 runs  12 599 ✅ 0 💤 0 ❌

Results for commit b87980e.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Validation Results

Version: ``

✅ Validation Steps

  • Build solution
  • Run tests
  • Build documentation
  • Dry-run NuGet packaging

📊 Artifacts

Dry-run artifacts have been uploaded and will be available for 7 days.


This comment was automatically generated by the PR validation workflow.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GenerateObjectPool attribute + ObjectPoolGenerator with 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.

Comment on lines +54 to +78
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);
}
Comment on lines +81 to +89
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
@JerrettDavis
JerrettDavis force-pushed the patterns/object-pool-486 branch from 79485d3 to b87980e Compare May 31, 2026 19:56
@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.53846% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.49%. Comparing base (85fa569) to head (b87980e).

Files with missing lines Patch % Lines
...rnKit.Generators/ObjectPool/ObjectPoolGenerator.cs 95.83% 5 Missing ⚠️
...atternKit.Core/Creational/ObjectPool/ObjectPool.cs 93.93% 4 Missing ⚠️
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     
Flag Coverage Δ
unittests 97.49% <96.53%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Summary
  Generated on: 05/31/2026 - 20:04:57
  Coverage date: 05/31/2026 - 20:02:00 - 05/31/2026 - 20:04:44
  Parser: MultiReport (12x Cobertura)
  Assemblies: 5
  Classes: 1727
  Files: 583
  Line coverage: 97.4%
  Covered lines: 46196
  Uncovered lines: 1223
  Coverable lines: 47419
  Total lines: 101230
  Branch coverage: 84.4% (14645 of 17347)
  Covered branches: 14645
  Total branches: 17347
  Method coverage: 97.2% (9021 of 9277)
  Full method coverage: 91.6% (8498 of 9277)
  Covered methods: 9021
  Fully covered methods: 8498
  Total methods: 9277

PatternKit.Core                                                                                                       96%
  PatternKit.Application.ActivityTracking.ActivityGateState                                                          100%
  PatternKit.Application.ActivityTracking.ActivityLease                                                              100%
  PatternKit.Application.ActivityTracking.ActivityRecord                                                             100%
  PatternKit.Application.ActivityTracking.ActivityTracker                                                            100%
  PatternKit.Application.Aggregates.AggregateCommandHandler<T1, T2, T3>                                              100%
  PatternKit.Application.Aggregates.AggregateCommandResult<T>                                                        100%
  PatternKit.Application.Aggregates.AggregateRoot<T1, T2>                                                            100%
  PatternKit.Application.AntiCorruption.AntiCorruptionLayer<T1, T2>                                                 90.4%
  PatternKit.Application.AntiCorruption.AntiCorruptionResult<T>                                                      100%
  PatternKit.Application.AuditLog.AuditLogAppendResult<T>                                                           85.7%
  PatternKit.Application.AuditLog.InMemoryAuditLog<T1, T2>                                                          95.4%
  PatternKit.Application.BoundedContexts.BoundedContextAdapter                                                       100%
  PatternKit.Application.BoundedContexts.BoundedContextCapability                                                   83.3%
  PatternKit.Application.BoundedContexts.BoundedContextDescriptor                                                   95.4%
  PatternKit.Application.ContextMaps.ContextMapDescriptor                                                           96.8%
  PatternKit.Application.ContextMaps.ContextMapRelationship                                                          100%
  PatternKit.Application.DataMapping.DataMapper<T1, T2>                                                             94.6%
  PatternKit.Application.DataMapping.DataMapperError                                                                  90%
  PatternKit.Application.DataMapping.DataMapperResult<T>                                                            84.6%
  PatternKit.Application.DomainEvents.DomainEventDispatcher<T>                                                      95.4%
  PatternKit.Application.DomainEvents.DomainEventDispatchResult                                                      100%
  PatternKit.Application.DomainServices.DomainServiceOperation<T1, T2>                                               100%
  PatternKit.Application.DomainServices.DomainServiceRegistry<T1, T2>                                                100%
  PatternKit.Application.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.EventualConsistency.EventualConsistencyEvaluation<T>                                       92.3%
  PatternKit.Application.EventualConsistency.EventualConsistencyMonitor<T>                                          97.2%
  PatternKit.Application.EventualConsistency.EventualConsistencyMonitorState<T>                                      100%
  PatternKit.Application.EventualConsistency.EventualConsistencyWatermarks<T>                                       96.7%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%
  PatternKit.Application.IdentityMap.IdentityMap<T1, T2>                                                             100%
  PatternKit.Application.IdentityMap.IdentityMapResult<T>                                                           92.8%
  PatternKit.Application.ManualTaskGates.ManualTaskGate<T>                                                          98.5%
  PatternKit.Application.ManualTaskGates.ManualTaskGateState<T>                                                      100%
  PatternKit.Application.ManualTaskGates.ManualTaskRecord<T>                                                        96.9%

@JerrettDavis
JerrettDavis merged commit caf68e1 into main May 31, 2026
12 checks passed
@JerrettDavis
JerrettDavis deleted the patterns/object-pool-486 branch May 31, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants