iliana / rust-crowbar

Wrapper to simplify writing AWS Lambda functions in Rust (using the Python execution environment)
https://docs.rs/crowbar
Apache License 2.0
197 stars 16 forks source link

Performance #30

Closed qm3ster closed 6 years ago

qm3ster commented 6 years ago

Any ideas about what the performance is like, especially cold start and network data?

naftulikay commented 6 years ago

I can get execution time of 400 microseconds using Serde to deserialize objects into structs and with one or two log events. It's wicked fast.

iliana commented 6 years ago

The main area where the performance comes from is in cpython-json; it could probably be made even faster if Lambda had a good "arbitrary binary" spec where the event was just passed to your binary as a JSON string, and you could handle deserializing it.

As it is with the Python execution environment, by the time our function gets invoked the JSON string has already been deserialized by Python.

(One of these days I'm going to look at how AWS implemented the Go execution environment, as at first glance it looks like you are pulling in libraries which do the JSON deserializing. Perhaps we can pretend to be a Go program and see a performance benefit.)

Ultimately the passthrough from Python into Rust and back again is very fast for Lambda functions which use reasonably sized objects. Additional performance improvements are likely to be unnecessary micro-optimization compared to the round-trip time of the Invoke call.

Let me know if you've got more questions.

naftulikay commented 6 years ago

Thanks for addressing this and explaining what the overhead is. It's already blazing fast but always appreciate an in depth explanation.