Skip to content

[BUG] Pydantic V2.11 Seems to cause up to x2.5 memory usage to ninja models build #1444

@M3te0r

Description

@M3te0r

Describe the bug
A clear and concise description of what the bug is.

Hi, during a dependencies upgrade work, upgrading both ninja and pydantic to last version (1.4, 2.11)

I've seen up to x2.5 in terms of memory allocation, in my case 1.2 GB, with pydantic 2.10 I was at 510 MB, at this point I don't know if it's ninja or pydantic istelf but i've seen that pydantic._internal._model_construction.complete_model_class / pydantic.plugin._schema_validator.create_schema_validator are memory intensive

A bit weird because 2.11 claim is to reduce memory allocation..

I've used memray to have some flamegraph representation:

Before (2.10):

Image

Image

Image

After (2.11)

Image

Image

Image

Versions (please complete the following information):

  • Python version: 3.13
  • Django version: 5.0.14
  • Django-Ninja version: 1.4.1
  • Pydantic version: 2.10/2.11

Note you can quickly get this by runninng in ./manage.py shell this line:

import django; import pydantic; import ninja; django.__version__; ninja.__version__; pydantic.__version__

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions