Skip to content

Decoder adapter caches grow without bound when models are created per request #174

Closed

Description

@lesnik512

The pydantic and msgspec decoders cache one adapter per model in a plain dict (src/httpware/decoders/_caching.py). The cache holds a strong reference to every model it has seen and never evicts. Code that builds a model per request, for example with pydantic.create_model, grows the cache, and keeps those classes alive, for the life of the decoder.

How to confirm: decode through 10,000 models made with create_model and watch len(decoder._adapters) and the process RSS.

Options if it reproduces: a bounded LRU, or documenting that response models must be long-lived. Either needs a check of what it costs on a cache hit, since the lookup runs on every decoded request.

Activity

  1. added
    bugSomething isn't working
    needs-triageMaintainer needs to evaluate this issue
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageMaintainer needs to evaluate this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions