refact: recycle objects through swag/pools - #280
Merged
Conversation
The pools here did what swag/pools does generically, in 1384 lines across a
release file and a debug one selected by build tag. They are now fifteen
declarations of pools.Pool[T], and the hand-written instrumentation gives way
to the shared one:
go test -tags poolsdebug ./...
That build tracks every borrow and redeem, panics on a double redeem, a
foreign redeem or a borrow of an object still checked out, and reports what
was borrowed and never given back. The suite passes under it, parallel
validation included.
Result implements pools.Resettable, so it is cleared when borrowed as it was
before, and now when redeemed as well: a result idling in the pool no longer
keeps a reference to the document it validated.
Results are borrowed straight from the pool rather than through a helper, so
that a leak is attributed to the code that borrowed it rather than to the
helper. Redeeming still goes through one, since the shared empty result was
never borrowed and must not be handed over.
The leak assertion, previously reachable only under the local build tag, now
runs in both modes and covers validating a specification, validating data
against a schema, and the nil-schema path that returns that empty result.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
force-pushed
the
refact/use-swag-pools
branch
from
August 9, 2026 09:52
2b21ae0 to
3f2102b
Compare
Parallel test with -race exhausts CI runners on windows and darwin. The path it is testing doesn't need multi-platform tests, so only linux will validate. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi
force-pushed
the
refact/use-swag-pools
branch
from
August 9, 2026 10:03
3f2102b to
5540162
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #280 +/- ##
==========================================
+ Coverage 92.93% 93.13% +0.19%
==========================================
Files 27 27
Lines 3498 3395 -103
==========================================
- Hits 3251 3162 -89
+ Misses 162 156 -6
+ Partials 85 77 -8 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pools here did what swag/pools does generically, in 1384 lines across a release file and a debug one selected by build tag. They are now fifteen declarations of pools.Pool[T], and the hand-written instrumentation gives way to the shared one:
That build tracks every borrow and redeem, panics on a double redeem, a foreign redeem or a borrow of an object still checked out, and reports what was borrowed and never given back. The suite passes under it, parallel validation included.
Result implements pools.Resettable, so it is cleared when borrowed as it was before, and now when redeemed as well: a result idling in the pool no longer keeps a reference to the document it validated.
Results are borrowed straight from the pool rather than through a helper, so that a leak is attributed to the code that borrowed it rather than to the helper. Redeeming still goes through one, since the shared empty result was never borrowed and must not be handed over.
The leak assertion, previously reachable only under the local build tag, now runs in both modes and covers validating a specification, validating data against a schema, and the nil-schema path that returns that empty result.
Change type
Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update
Short description
Fixes
Full description
Checklist