Leveraging modern low-level: a Rust backend for PureScript

News #16:

A few adjustments are underway, but all tests for approximately 54 modules are now passing (purust-*). Next step: the official tests.

Very interesting project! Testing it out to speed up a mostly pure code project (~50K LOC PureScript) that I’m running on NodeJS. I was actually able to compile most of the project and even run some unit tests. Not enough to get a sense of the performance comparison but it feels like it’s close :slight_smile:

Cut some tickets to the repo with the findings. 2 I was able to work around. Another one not (the freeap one). Hopefully this is helpful!

3 Likes

Thank you George @gwwatkins :slight_smile: :heart:

I didn’t think this would work on projects right away. Exciting news! Maybe we’re closer to seeing the light at the end of the tunnel than I thought.

Thank you so much for your support and your issues; I’ll take a close look at them. Even though gopurs is my priority right now, purust is the project that seems most interesting to me for PureScript in the long run, so I’m taking all of this very seriously.

Edit: Fixed all issues. I’ll probably give you a complete feedback on github by the end of the day (right now on a train).

2 Likes

Thank you Kevin for the super fast fixes and replies!

Looks like the input was met positively :slightly_smiling_face: I can continue give a bits of feedback as I work on this on the side :handshake:

I could try the go back end as well, though I liked the idea of porting some of the tightest loops to Rust. Since one of the optimizations that worked for this project was some some manipulating the data layout using JavaScript arrays.

1 Like

Absolutely, yes: I’m very happy to see people giving it a try, and that will help me a lot. It’s quite a large project, and every piece of feedback will be a great help to me. I’ll eagerly welcome all your feedback. Feel free to run your tests. Whenever you feel like it, I won’t mind at all (quite the opposite).

I’m going to focus my immediate efforts on the Array Processing test for Rust (+ Array Indexing, recently added). I’ll let you know when it’s fully optimized and ready to go, so you can test it :slight_smile:

1 Like

I took advantage of a bout of unwanted insomnia to improve the performance of the Array Processing test, which is now 100x faster: 25 μs → 0.25 μs (vectorization, fusion…). I’m actually still working on improving it, to get even closer to imperative C. :crab:

But I think you can already start testing things on your side, since it’s now much better than JS. I hope my optimizations address your own bottlenecks. (If you notice anything running slowly on Arrays, please don’t hesitate to let me know so I can add some tests, for example.)

purust branch edge (2b15ad6)
purust-arrays branch master (23600e8)
purust-foldable-traversable branch master (00be4d3)
purescript-backend-optimizer(-purust) branch edge-purust (3fd2eea)

1 Like

0.25 μs → 0.0366 µs. Now better than “hand-written” imperative C, in the benchmark. :wink:

You can find more here: Perf improvements on Arrays (WIP) · Issue #4 · 0x000000000000000000001/purust · GitHub

2 Likes

@harryprayiv I’ve started a linearity lab to explore several compile-time approaches for purust, particularly ways to express and check Rust ownership constraints on the PureScript side of the FFI where needed.

An interesting repo actually goes that way: GitHub - nfgrusk/purescript-substructural: Substructural types in PureScript. · GitHub

I’ll give you my conclusions soon.


Edit:

Currently diving in this post by Freeman.

He gave a clean example here.

The b8x project is Rust-ready, and I’m currently integrating indexed monads & substructural snippets. They are probably the best approaches. I’ll send you file links soon, to give an concrete example of what it looks like.

2 Likes

Indexed monads are handy for writing application code, but the FFI suffers from significant bloat. Using the substructural library as much as possible helps keep the code more concise, but one thing that was notably missing was a do notation: which I added to the library by forking it (among other things). It’s still very experimental and imperfect, but it works.

I’ve started integrating it haphazardly into the b8x project, and it’s still pretty messy, since the work needed to make the FFIs idiomatic hasn’t been done yet. Just in case, I’m making the code available anyway.

I’ll come back to this when gopurs is ready: I’ll clean everything, and provide a clear guide on the proper methodology for Rust FFIs.

2 Likes

@0x000000000000000000 no updates for almost a week? We want to know!

2 Likes

@i-am-the-slime

I had the flu for a few days…

But I’m working on the “nixification” of gopurs, and before that: the incremental build. It’s an essential (and difficult) step, even though it seems small on paper. :slight_smile:

I’ve also been having a very friendly exchange with @erikagain: he told me that @rightfold himself has been made aware of these small Rust-oriented/influenced substructural projects (he’s also a Rust expert, FWIK). Maybe he’ll find them interesting, and we could work together someday on these topics when I return to purust.

1 Like

News #17:

This could significantly change purust’s DX if it were to come to fruition and live up to its promise:

Something to keep an eye on…