Skip to content

feat(pool): adds pooling support for well-known type wrappers and maps - #172

Open
sgg wants to merge 4 commits into
planetscale:mainfrom
sgg:sgg/wkt-pooling
Open

sgg wants to merge 4 commits into
planetscale:mainfrom
sgg:sgg/wkt-pooling

Conversation

@sgg

@sgg sgg commented Oct 1, 2026

Copy link
Copy Markdown

This PR makes three changes to the generator:

  1. It adds pool support for well-known types (WKT) wrappers.
  2. It adds pool support for maps (reusing work from features/pool: reuse map type fields #156)
  3. It updates the unmarshaling logic such that maps are pulled from a pool when appropriate.

The commits reflect the changes in the order above. I elected to bundle them because all three changes are small and related. I'm happy to break these into separate PRs if folks feel that's appropriate. I'm also happy to make any doc updates that seem relevant.

sgg added 4 commits September 30, 2026 17:46
**Context**

Today users of vtproto benefit from fully unrolled ser/des but
cannot take advantage of pooling, creating GC churn where there would
otherwise be none.

This diff:

* Adds pooling support to the generator for well-known types.
* Updates Makefile w/ pooling arguments for gen-wkt and gen-testproto
* Adds additional fields to WKTNestedPool test type for testing
* Regenerates test wkt and test protos
* Adds IsLocalWrapper helper func to generator
* Adds new unit tests exercising cloning behavior

The new pooling code is inert for existing stubs; as such this change
should be backwards compatible. Users can leverage this by regenerating
their stubs.

**⚠️  Caveats ⚠️**

While the code is backwards compatible, this is a _material change in
behavior_. Previously there were cases where calling `ResetVT` on a type
containing a singular WKT would simply clear the pointer. This meant it
was safe to share/reuse WKT objects in certain cases. This is no longer
true; all the same terms and conditions that apply to other pooled types
apply to WKT wrappers.

Currently Struct's do not benefit much from this as we do not have
pooling for maps. This will be addressed in a follow on change.
This diff refactors planetscale#156 to add support for pooling maps.

**Caveats**

* Just like with pooled slices, pooled maps do not shrink. This is a
  footgun we may want to document explicitly.
This diff regenerates the wkt wrappers with map pooling support.
This diff updates the generated unmarshal code to pull map values from
pools when pooling is enabled for both parent messages and the value
type.

**Caveats**

* If a given key is repeated, the old pooled value will be dropped and
  picked up by GC. This is done for simplicity.
* If unmarshal fails partway through, any values pulled from the pool
  will be left for GC. This behavior matches what happens with oneof's.
@sgg

sgg commented Oct 6, 2026

Copy link
Copy Markdown
Author

@mattlord I'd appreciate some eyes on this whenever you get a chance <3

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