Categories
Blog

LLM as a compiler

Recently I have been using LLMs to explore different ideas related to syncing two nodes. I wanted to see how far I could take the setsum idea. The first tries last year was fraught with disappointing. The LLMs needed a lot of hand-holding to get things into shape. Eventually I settled on a stable foundation (tests) and code base and that made it easier to iterate on performance improvements. This resulted in a 10x speedup compared to the initial version.

Lately I have been using mainly claude to explore a sync protocol based on setsums. The protocol has some nice properties in that the overhead in the normal case is very close to optimal and it can handle deletes without growing forever using epochs falling back to a tree based sync on divergence (same case for node errors).

Today I wanted to explore if it was possible to run setsum in the browser using WASM. My first try was to simply compile the c# version to wasm. This pulled in the whole .net GC and a lot of other .net stuff, so the resulting wasm file was gigantic (~10MB). Seeing as the whole implemention of setsum is quite simple and small (~100 lines of code) maybe the LLM could translate it directly to WASM. It settled on assemblyscript that can be compiled that to WASM. This resulted in a 1.7KB file which to my surprise, was even faster than the c# version running natively on my machine. Almost twice as fast using the same SIMD tricks as the c# version does.

And no, this blog post was not written a LLM 😉

Leave a Reply

Your email address will not be published. Required fields are marked *