Skip to content

feat: factory for generic sync.Pool usage, with safety test mode - #215

Merged
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:feat/pools
Jun 29, 2026
Merged

feat: factory for generic sync.Pool usage, with safety test mode#215
fredbi merged 1 commit into
go-openapi:masterfrom
fredbi:feat/pools

Conversation

@fredbi

@fredbi fredbi commented Jun 29, 2026

Copy link
Copy Markdown
Member

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.73239% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.25%. Comparing base (ce8f066) to head (3c99f2d).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
pools/pools.go 86.91% 10 Missing and 4 partials ⚠️
pools/debug_on.go 91.01% 5 Missing and 3 partials ⚠️
pools/shared/shared.go 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #215      +/-   ##
==========================================
- Coverage   92.54%   92.25%   -0.29%     
==========================================
  Files          54       57       +3     
  Lines        2603     2816     +213     
==========================================
+ Hits         2409     2598     +189     
- Misses        148      165      +17     
- Partials       46       53       +7     

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

This PR introduces a new utility module to manipulate sync.Pools more
easily.

It introduces generic wrapper to create pools of any type more concisely.

There is a "RedeemablePool" wrapper to keep the "return to pool" closure
readily available without needing further allocations (use-case: defer
redeem()).

A "SlicePool" allows to manipulate pools of slices more easily, and
better control their growth / reuse of reallocated slices.

Additional safeties are built in that fail early on typical pool errors (e.g.
redeem a pointer that has not been borrowed).

A "poolsdebug" build tag enables pool instrumentation to run tests with
more assertions about the correct usage of pools (panics if a wrong
pattern is detected).

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi
fredbi merged commit d4bd1af into go-openapi:master Jun 29, 2026
21 checks passed
@fredbi
fredbi deleted the feat/pools branch June 29, 2026 16:07
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.

1 participant