Shopify Functions WASM using RUST - Should be using Crystal!

With Shopify functions, a RUST deliverable is run on WASM with JS handling the front end.

This is something Crystal would be perfect for, not only is RUST a lot more difficult to program with, but Shopify is a heavy Ruby development shop & Crystal is just as fast as RUST in these scenarios. Shopify could have allowed developers to build an unix executable & just run that at the edge, I assume this runs on Cloudflare.

WASM support should be a top priority for Crystal?

It seems any WASI compatible language can work. Crystal would then be perfect for this.

1 Like

Also very relevant:

I consider this not always the tech issue.

Maybe manas consider contribute Crystal to community, as rust get reborn after Mozilla contribute rust to https://foundation.rust-lang.org

1 Like

Yes, if there was this level of funding it would make a lot of sense. Of course, the development experience vs RUST for Shopify Ruby devs coming from standard Ruby would be immense. If you hearing this Shopify, you should be a member ;)

Crystal is just as fast as RUST in these scenarios.

Would be interesting to see that proved out. The system is in developer preview and we have a documented spec for adding new languages if folks want to give it a shot. We also have a tool for testing the performance/memory/module size.

5 Likes

See the “Roadmap to WebAssembly support” GitHub issue for some explanations of difficulties and possible solutions in adding a WASM target for Crystal. Before reading it, I thought that garbage collection would be a huge issue, but apparently the GC can be compiled to WASM as well.

Related, I think it’s a bit bold to say that Crystal will definitely be faster than Rust in a given scenario without doing reasonable timing comparisons (and not just toy benchmarks). Garbage collection requires performance overhead, so that will always cost Crystal programs in terms of speed, whereas the same things that make Rust difficult to learn and use also make it manage memory safely without GC overhead. In most cases, I think that Crystal is close enough in performance to Rust that the developer experience makes it worth using Crystal instead, but Rust and Crystal are both tools suited to particular applications, and I’m not sure it’s clear yet whether Crystal will be as suited for targeting WASM as Rust is. I sure hope so, but we’ll have to see.

7 Likes

Maybe it’s better to say “Would be faster to write” & “Easier code to understand” instead :sweat_smile:

1 Like

From what I could see Shopify functions are short-lived, i.e. they start, read input, write output, and exit everytime. This is a good design for WebAssembly and this means that a GC won’t even need to run, most likely. Unless you are doing something really memory intensive and above 1 second or so. Having the GC disabled will actually make the code run faster.

Also the Shopify interface seems to be quite simple: read JSON from stdin, write JSON to stdout and log to stderr. If that’s the case you can already use Crystal today. The stdlib support those operations for WASM.

If someone could give it a try, it would be awesome.

4 Likes