samkelleher / wasm-embed

Get fast Cloudflare Worker response times by embedding static website assets directly using WebAssembly.
https://samkelleher.com/portfolio/Ultra-fast-response-times-serving-static-files-with-WebAssembly-Workers
9 stars 1 forks source link

This vs CfWorkers-Sites? #1

Open tomByrer opened 4 years ago

tomByrer commented 4 years ago

I found this repo by hunting for updates to my Awesome Cloudflare Workers. Today I also found out about Cloudflare's sites. Can you please comment on how they might contrast &/or compliment each other? I'm mostly looking for technical differences; speed differences, how much memory & execution bounds you can hit for a busy site, etc.

cheers

samkelleher commented 4 years ago

Good question @tomByrer .

I've added as part of this embed test uploading the same sample file to a KV namespace, and updating the template to load the sample image, one from the KV store, and the other from the binary embedded within the script.

The first load had the most dramatic speed difference, after this, reloading multiple times, for me, the KV hosted image loaded consistently slower than the embedded version.

This would make sense since the embedded version is there in memory ready to read, where as the KV version has to internally go within cloudflares infra, locate and load the item from the store.

Screenshot 2020-02-13 at 19 42 24

For me, the embedded version always loaded the same around ~10-40ms.

The KV version loaded around ~20-400ms slower than that.

tomByrer commented 4 years ago

Oh wow, thanks so much for your research!

But I'm not sure if the official Worker Sites uses the KV store, rather they use a permanent cache maybe? But I have seen older Worker scripts that do use KV store, so this would be superior for many use cases.