Skip to content

refact: recycle objects through swag/pools - #280

Merged
fredbi merged 2 commits into
go-openapi:masterfrom
fredbi:refact/use-swag-pools
Aug 9, 2026
Merged

refact: recycle objects through swag/pools#280
fredbi merged 2 commits into
go-openapi:masterfrom
fredbi:refact/use-swag-pools

Conversation

@fredbi

@fredbi fredbi commented Aug 9, 2026

Copy link
Copy Markdown
Member

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.

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.

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
fredbi force-pushed the refact/use-swag-pools branch from 2b21ae0 to 3f2102b Compare August 9, 2026 09:52
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
fredbi force-pushed the refact/use-swag-pools branch from 3f2102b to 5540162 Compare August 9, 2026 10:03
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.13%. Comparing base (83d7d4e) to head (5540162).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
schema_props.go 46.66% 8 Missing ⚠️
validator.go 81.81% 4 Missing ⚠️
default_validator.go 80.00% 2 Missing ⚠️
example_validator.go 80.00% 2 Missing ⚠️
formats.go 66.66% 1 Missing ⚠️
result.go 87.50% 1 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@fredbi
fredbi merged commit 02b8f94 into go-openapi:master Aug 9, 2026
21 checks passed
@fredbi
fredbi deleted the refact/use-swag-pools branch August 9, 2026 10:20
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