# Shopify Functions WASM using RUST - Should be using Crystal!

**URL:** <https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709>\
**Category:** Community\
**Created:** [June 22, 2022, 11:53pm UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709 "2022-06-22T23:53:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![codies](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@codies](https://forum.crystal-lang.org/u/codies)\
**Post date:** [June 22, 2022, 11:53pm UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/1 "2022-06-22T23:53:23Z")

</div>

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.

> **[Shopify Functions overview](https://shopify.dev/api/functions)**
>
> Learn about how Shopify Functions work and the benefits of using Shopify Functions.

---

<div class="post-metadata">

**Author:** ![codies](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@codies](https://forum.crystal-lang.org/u/codies)\
**Post date:** [June 23, 2022, 12:23am UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/2 "2022-06-23T00:23:25Z")

</div>

Also very relevant:

> [@WebAssembly potential use cases](https://forum.crystal-lang.org/t/webassembly-potential-use-cases/4522/7):
>
> Serverless functions with WebAssembly seem to have a bright future. We are implementing a [WebAssembly platform](https://shopify.engineering/shopify-webassembly) here at Shopify, you already pointed out Cloudflare, and there are others such as [Fermyon](https://www.fermyon.com/). Based on my quick POC this week, Crystal has a much friendlier developer experience than other existing options like Rust.

---

<div class="post-metadata">

**Author:** ![zw963](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/zw963/32/1623_2.png) [@zw963](https://forum.crystal-lang.org/u/zw963)\
**Post date:** [June 23, 2022, 6:52am UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/3 "2022-06-23T06:52:44Z")

</div>

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](https://foundation.rust-lang.org/)

---

<div class="post-metadata">

**Author:** ![codies](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@codies](https://forum.crystal-lang.org/u/codies)\
**Post date:** [June 23, 2022, 7:05am UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/4 "2022-06-23T07:05:24Z")

</div>

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 ;)

 ![Screen Shot 2022-06-23 at 5.04.14 pm](https://canada1.discourse-cdn.com/flex036/uploads/crystal_lang/original/2X/8/89d96fff1ae968e2d2b32e289f24bb013963fcc5.png)

---

<div class="post-metadata">

**Author:** ![DuncanUszkay1](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/duncanuszkay1/32/1675_2.png) [@DuncanUszkay1](https://forum.crystal-lang.org/u/DuncanUszkay1)\
**Post date:** [June 24, 2022, 4:44pm UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/5 "2022-06-24T16:44:06Z")

</div>

> 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](https://shopify.dev/api/functions/reference/webassembly-api) if folks want to give it a shot. [We also have a tool for testing the performance/memory/module size.](https://github.com/shopify/function-runner)

---

<div class="post-metadata">

**Author:** ![RespiteSage](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/respitesage/32/793_2.png) [@RespiteSage](https://forum.crystal-lang.org/u/RespiteSage)\
**Post date:** [June 24, 2022, 5:30pm UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/6 "2022-06-24T17:30:38Z")

</div>

See the [“Roadmap to WebAssembly support” GitHub issue](https://github.com/crystal-lang/crystal/issues/12002) 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.

---

<div class="post-metadata">

**Author:** ![codies](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@codies](https://forum.crystal-lang.org/u/codies)\
**Post date:** [June 25, 2022, 2:37am UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/7 "2022-06-25T02:37:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lbguilherme](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/lbguilherme/32/1484_2.png) [@lbguilherme](https://forum.crystal-lang.org/u/lbguilherme)\
**Post date:** [August 5, 2022, 10:47am UTC](https://forum.crystal-lang.org/t/shopify-functions-wasm-using-rust-should-be-using-crystal/4709/8 "2022-08-05T10:47:50Z")

</div>

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.
