9 ms·
Python Workers redux: fast cold starts, packages, and a uv-first workflow
- jtbaker 10mo ago``` BREAKING CHANGE The following packages are removed from the Pyodide distribution because of the build issues. We will try to fix them in the future: arro3-compute arro3-core arro3-io Cartopy duckdb geopandas ... polars pyarrow pygame-ce pyproj zarr ``` https://pyodide.org/en/stable/project/changelog.html#version-0-28-0 https://pyodide.org/en/stable/project/changelog.html#version... Bummer, looks like a lot of useful geo/data tools got removed from the Pyodide distribution recently. Being able to use some of these tools in a Worker in combination with R2 would unlock some powerful server-side workflows. I hope they can get added back. I'd love to adopt CF more widely for some of my projects, and seems like support for some of this stuff would make adoption by startups easier.
- jeff17robbins 10mo agoThe comparison with AWS Lambda seems to ignore the AWS memory snapshot option called "SnapStart for Python". I'd be interested in seeing the timing comparison extended to include SnapStart.
- killingtime74 10mo ago"SnapStart for Python" costs extra though. If we are paying then you can even have prewarmed Python lambdas with no cold start on AWS (Provisioned Concurrency).
- Yacoby 10mo agoUnless I misunderstand, AWS SnapStart and their memory snapshots are the same feature (taking memory snapshots to speed up cold start). It doesn't seem a fair comparison to ignore this and my assumption is because AWS Lambda SnapStart is faster.
- dom96 10mo agoIt wasn't an intentional omission, we weren't aware of this feature in AWS Lambda. The blog post has been updated to reflect that the numbers are for Lambda without SnapStart enabled. Python Workers use snapshots by default and unlike SnapStart we don't charge extra for it. For many use cases, you can run Python Workers completely for free on our platform and benefit from the faster cold starts.
- killingtime74 10mo agoI think it's fair because AWS charges extra for it. They are comparing the baseline product of all three platforms. Why should we take paid add ons into account for 1 platform. As I mentioned, if you are ok with paying, then you should also compare Provisioned concurrency on AWSbas well, which has 0 cold start (they keep a prewarmed lambda for you). Product comparisons are not purely technical in nature. As a user, if im paying extra, I would much rather the 0 cold start than just a reduced cold start especially with all these additional complexities.
- laurencerowe 10mo agoIn the linked detailed benchmark results they include Lambda SnapStart which seems to be faster than Cloudflare: > AWS Lambda (No SnapStart) Mean Cold Start: 2.513s Data Points: 1008 > AWS Lambda (SnapStart) Mean Cold Start: 0.855s Data Points: 17 > Google Cloud Run Mean Cold Start: 3.030s Data Points: 394 > Cloudflare Workers Mean Cold Start: 1.004s Data Points: 981 https://cold.edgeworker.net https://cold.edgeworker.net
- saikiran-a1 10mo agonice
- BiteCode_dev 10mo agoAnybody using it for something serious ? I can't see a use case beyond I need a quick script running that is not worth setting up a vps.
- pedrozieg 10mo agoThe most interesting bit here is not the “2.4x faster than Lambda” part, it is the constraints they quietly codify to make snapshots safe. The post describes how they run your top-level Python code once at deploy, snapshot the entire Pyodide heap, then effectively forbid PRNG use during that phase and reseed after restore. That means a bunch of familiar CPython patterns at import time (reading entropy, doing I/O, starting background threads, even some “random”-driven config) are now treated as bugs and turned into deployment failures rather than “it works on my laptop.” In practice, Workers + Pyodide is forcing a much sharper line between init-time and request-time state than most Python codebases have today. If you lean into that model, you get very cheap isolates and global deploys with fast cold starts. If your app depends on the broader CPython/C-extension ecosystem behaving like a mutable Unix process, you are still in container land for now. My hunch is the long-term story here will be less about the benchmark numbers and more about how much of “normal” Python can be nudged into these snapshot-friendly constraints.
- sandruso 10mo agoI'm betting against wasm and going with containers instead. I have warm pool of lightweight containers that can be reused between runs. And that's the crucial detail that makes or breaks it. The good news is that you can lock it down with seccomp while still allowing normal execution. This will give you 10-30ms starts with pre-compiled python packages inside container. Cold start is as fast as spinning new container 200-ish ms. If you run this setup close to your data, you can get fast access to your files which is huge for data related tasks. But this is not suitable for type of deployment Cloudflare is doing. The question is whether you even want that global availability because you will trade it for performance. At the end of the day, they are trying to reuse their isolates infra which is very smart and opens doors to other wasm-based deployments.
- resiros 10mo agoVery interesting but the limitation on the libraries you can use is very strong. I wonder if they plan to invest seriously into this?
- wg0 10mo agoIf anyone from cloudflare comes here - it's not possible to create D1 databases on the fly and interact them because databases must be mentioned in the worker bindings. This hampers the per user databases workflow. Would be awesome if a fix lands.
- ashwindharne 10mo agoI'm always a little hesitant to use D1 due to some of these constraints. I know I may not ever hit 10GB for some of my side projects so I just neglect sharding, but also it unsettles me that it's a hard cap.
- dom96 10mo ago(I work at Cloudflare, but not on D1) I believe this is possible, you can create D1 databases[1] using Cloudflare's APIs and then deploy a worker using the API as well[2]. 1 - https://developers.cloudflare.com/api/resources/d1/subresources/database/methods/create/ https://developers.cloudflare.com/api/resources/d1/subresour... 2 - https://developers.cloudflare.com/api/resources/workers/subresources/scripts/methods/update/ https://developers.cloudflare.com/api/resources/workers/subr...
- wg0 10mo agoThank you! That's great and it is possible but... With some limitations. The idea is from sign up form to a D1 Database that can be accessed from the worker itself. That's not possible without updating worker bindings like you showed and further - there is an upper limit of 5000 bindings per worker and just 5000 users then becomes the upper limit although D1 allows 50,000 databases easily with further possible by requesting a limit increase. edit: Missed opening.
- ewuhic 10mo agoHey, would you happen to know if/when D1 can get support for ICU (https://sqlite.org/src/dir/ext/icu https://sqlite.org/src/dir/ext/icu) and transactions?
- 10mo ago
- silverwind 10mo agoI wish they would contribute stuff like this memory snappshotting to CPython.
- jitl 10mo agoIt relies entirely on the WebAssembly runtime, see the discussion of how ASLR problems don’t occur with WASM. Doing this with WASM is pretty easy, doing it with system memory is quite tricky.
- scottydelta 10mo agoIt’s 2025 and choosing a region for your resources is still an enterprise feature on cloudflare. In contrast, AWS provides this as the base thing, you choose where your services run. In a world where you can’t do anything without 100s of compliance and a lot of compliances require geolocation based access control or data retention, this is absurd.
- NicoJuicy 10mo agoThat's basically not how Cloudflare works. Your app works distributed/globally on the go. Additionally, every Enterprise feature will become available in time ( discussed during their previous quarter earnings). It will be bound to regions ( eg. Eu)
- baq 10mo agoit's only absurd if you don't want to pay cloudflare money
- scottydelta 10mo agoYou can't pay and get it even if you want. There is no paid business plan that supports this. You have to be millions of dollars worth of enterprise on their enterprise plan to get it through your dedicated account manager.
- deleted 10mo ago[deleted]
- cloudflare728 10mo agoI hope Cloudflare improve Next.js support on Workers. Currently pagespeed.web.dev score drops by around 20 than self hosted version. One of the best features of Next.js, Image optimization doesn't have out of the box support. You need separate image optimization service that also did not work for me for local images (images in the bundle).
- randomtoast 10mo agoOne of my biggest points of criticism of Python is its slow cold start time. I especially notice this when I use it as a scripting language for CLIs. The startup time of a simple .py script can easily be in the 100 to 300 ms range, whereas a C, Rust, or Go program with the same functionality can start in under 10 ms. This becomes even more frustrating when piping several scripts together, because the accumulated startup latency adds up quickly.
- nickjj 10mo ago> The startup time of a simple .py script can easily be in the 100 to 300 ms range I can't say I've ever experienced this. Are you sure it's not related to other things in the script? I wrote a single file Python script, it's a few thousand lines long. It can process a 10,000 line CSV file and do a lot of calculations to the point where I wrote an entire CLI income / expense tracker with it[0]. The end to end time of the command takes 100ms to process those 10k lines, that's using `time` to measure it. That's on hardware from 2014 using Python 3.13 too. It takes ~550ms to fully process 100k lines as well. I spent zero time optimizing the script but did try to avoid common pitfalls (drastically nested loops, etc.). [0]: https://github.com/nickjj/plutus https://github.com/nickjj/plutus
- tlyleung 10mo agoJust a guess - but perhaps the startup time is before `time` is even imported?
- williadc 10mo ago`time` is a shell command that you can use to invoke other commands and track their runtime.
- zahlman 10mo ago> I can't say I've ever experienced this. Are you sure it's not related to other things in the script? I wrote a single file Python script, it's a few thousand lines long. It's because of module imports, primarily and generally. It's worse with many small files than a few large ones (Python 3 adds a little additional overhead because of needing extra system calls and complexity in the import process, to handle `__pycache__` folders. A great way to demonstrate it is to ask pip to do something trivial (like `pip --version`, or `pip install` with no packages specified), or compare the performance of pip installed in a venv to pip used cross-environment (with `--python`). Pip imports literally hundreds of modules at startup, and hundreds more the first time it hits the network.
- rcarmo 10mo agoPyodide is a great enabler for this kind of thing, but most of the libraries I want to use tend to be native or just weird. Still, I wonder how fast things like Pillow, Pandas and the like are these days—-benchmarks would be nice.
- ianberdin 10mo agoI still don’t get, what is the use case for cloudflare workers or lambda? I used both for years. Nothing beats VPS/bare metal. Alright, they give lower latency, and maybe cheaper and big nightmare for managing at the same time. Hello to micro services architecture.
- maccard 10mo agoScale down to actual 0, really easy edge distribution, stupidly simple to deploy to. That's really it.
- acdha 10mo agoThink about how often that box needs patching for code outside of your app and you’re talking load-balancing, autoscaling, etc. to avoid downtime or overloads, but also paying for idle capacity. Then, of course, you have to think about security partitions if anything you run on that box shouldn’t have access to everything else. None of that is unknown, we have decades of experience and tooling dealing with it, etc. but it’s a job that you can just choose not to have and people often do, especially for things which are bursty. There’s something really nice about not needing to patch anything for years because all you’re using is the Python stdlib and scaling from zero to many, many thousands with no added effort.
- orliesaurus 10mo agoChecked out the Cloudflare post... they now support Pyodide-compatible packages through uv... so you can pull in whatever Python libs you need, not just a curated list. ALSO the benchmarks show about a one second cold start when importing httpx, fastapi and pydantic... that's faster than Lambda and Cloud Run, thanks to memory snapshots and isolate-based infra. BUT the default global deployment model raises questions about compliance when you need specific regions... and I'd love to know how well packages with native extensions are supported.