Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydantic V2 slower on AWS lambda #7393

Closed
1 task done
matthieudesprez opened this issue Sep 11, 2023 · 4 comments
Closed
1 task done

Pydantic V2 slower on AWS lambda #7393

matthieudesprez opened this issue Sep 11, 2023 · 4 comments
Assignees
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable

Comments

@matthieudesprez
Copy link

matthieudesprez commented Sep 11, 2023

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Hello,

We've migrated from v1 to v2 in our codebase, and we've experienced slower execution times on AWS lambda, along with memory consumption increase.

image

I'm struggling to reproduce this locally, so for now I thought I could already share it here in case someone has a similar issue.

It doesn't seem to be related to cold start, as even warm lambdas are affected, but it looks like the most "wasted" time happens during the beginning of the execution. It takes 20s to do something I still can't figure.

image

Example Code

No response

Python, Pydantic & OS Version

pydantic version: 2.1.1
        pydantic-core version: 2.4.0
          pydantic-core build: profile=release pgo=false mimalloc=true
                 install path: .../lib/python3.8/site-packages/pydantic
               python version: 3.8.12 (default, Sep  5 2022, 15:57:41)  [Clang 13.1.6 (clang-1316.0.21.2.3)]
                     platform: ...
     optional deps. installed: ['email-validator', 'typing-extensions']
@matthieudesprez matthieudesprez added bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable labels Sep 11, 2023
@adriangb
Copy link
Member

Slow cold starts are a known problem.
Memory usage was a problem but should have been solved by pydantic/pydantic-core#900.

I see you're using pydantic-core 2.4.0. Can you try updating to the latest pydantic (v2.3.0 as or today) and hence the latest pydantic-core?

@matthieudesprez
Copy link
Author

Thanks for your answer. It looks better indeed since upgrading to the last version.

Can we do something in order to optimise the initialisation time ?

@adriangb
Copy link
Member

Just curious, are you using FastAPI?

@matthieudesprez
Copy link
Author

Not on this lambda, it's actually triggered by Appsync as a resolver for a GraphQL Query, but it does use 5 levels depth nested models.

Last update seems to work better for now, so I'm gonna close this issue, thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 unconfirmed Bug not yet confirmed as valid/applicable
Projects
None yet
Development

No branches or pull requests

2 participants