Posts

Python on Serverless: Pragmatic Hacks for Peak Performance

PyConES 2025 · Seville, Spain

·
Updated
·
2 min read

Real-world Python performance optimizations from our flight search engine at Perk, presented with Alberto Maldonado at PyConES 2025 in Seville.

Python
Conferences
Serverless
Performance
PyConES 2025 at Universidad Pablo de Olavide, Seville, Spain
Table of Contents

If you missed the live session, the full recording is available above.


Key takeaways

  • Disabling Python’s garbage collector at the right moment took one function from 1.2 seconds to 300 milliseconds.
  • An async post-execution pattern runs cleanup after the Lambda handler returns, without adding latency for the user.
  • Replacing Pydantic with TypedDict, covered by Alberto Maldonado, pays off when deserializing thousands of objects per request: the question is when you need dynamic validation at all.

We were building an API that processes thousands of flight offers per request: deserializing, enriching, transforming. At some point the latency became a problem and we had to look into it properly. We ran profilers, read the CPython docs more carefully than we ever had, and started making changes.

Alberto Maldonado and I brought that story to PyConES 2025.

I covered the Python memory model, how the garbage collector behaves in short-lived environments like Lambda, and why disabling it at the right moment matters. One function went from 1.2 seconds to 300 milliseconds just from that. I also walked through the async post-execution pattern we use to run cleanup after the handler returns without adding latency to the user.

Alberto covered the Pydantic to TypedDict migration. When you are deserializing thousands of objects per request, validation overhead adds up fast. The case for TypedDict is not about correctness versus speed, it is about understanding when you actually need dynamic validation and when you do not.

We also came back with something we did not expect. A conversation with another speaker about Streamlit for backoffice tooling made us think. The idea: you already write Python, so why bring in a separate stack for internal UIs? We tried it after getting back. It was easier than expected and delivered more than we thought it would. That is the kind of thing you do not know you are going to take home until you are already on the train back.

Explore More

🗓️ Conference website: 2025.es.pycon.org

🎤 View the abstract: Talk details on PyConES