The Carcinization of Go Programs
xeiaso.net
xeiaso.net
The functional requirement here is to take some HTML, parse it and emit slack flavoured markdown.
Involving WASM / Rust / cross compiling stuff and fucking around with a build tool chain should not even be being discussed anywhere as a solution for this. I mean it's fine as a toy but the problem is that half the industry doesn't have any idea what's a good idea and what isn't from an engineering perspective when it comes to solving problems and this will be taken as gospel on how to solve the thing.
What we have here is a Rube Goldberg machine, not a cleanly solved engineering problem.
Is the definition of "how do I get promoted in a company where I don't care if it survives the next five years", not "a cleanly solved engineering problem".
It's pretty difficult and expensive to build one stack, let alone three and onboard another tool.
I understand that cgo has significant per-call overhead, aside from all the other curses it implies, does wasm/wazero have the same issue or not?
I’m not sure how to fix this but I’m also tired of pretending it’s not a chronic problem.
And if rewrite is Rust->Go way, also continual effort of porting any bugfixes in upstream lib.
I dare to say more complex toolchain is the easier and less time consuming part.
I wouldn't do it in this particular case (converting with mastodon powered html is probably simple enough) but it wouldn't be a terrible solution in some cases.
What's more interesting is if you use same method for app plugins, now you can compile anything in WASM and as long as it have right hooks it can be used in your app as a plugin
This is more work up front, but it’s better engineering.
> easier and less time consuming
Have some pride, jesus christ.
I'd rather work on software that depends on three different tech stacks that are well understood and used by many, than software that depends on a single niche tech stack.
For a system architect or senior developer it's very interesting to know I might glue a (not so trivial) Rust codebase into my Go program so easily. For people actually working on Go, Rust, WASM, etc., these are also experiments to evaluate the ergonomics, performance, etc. of all the tooling. For someone who wants to learn how FFIs work, this is a great tutorial.
But I'm certain I will now get at least one mid-level dev or interview candidate actually try to do this, in a similarly trivial case. And I will have to explain yes you already wrote the whole build pipeline but no we're not going to maintain it, and yes the blog post says it's fast but it's not really that fast, and etc. etc. It's bad enough every time I have to hear "it's just one Python script, what could it cost?", but the more complex it gets the more energy it takes to genuinely convince (rather than merely authoritatively declare) people not to do it, and the limit there seems unbounded.
> What we have here is a Rube Goldberg machine, not a cleanly solved engineering problem.
And what _we_ have here is unfounded indignation over a perfectly fine way to solve a problem. People have been using linked libraries to re-use code across languages since forever, it's fine. This solution isn't very different, it just makes shipping easier.
As a parting comment, "sound software architecture" is not a decided upon principle which can be empirically determined, and if it was we'd all be out of a job.
People have been doing it forever, but people have also hated it forever. Twenty years ago you saw SWIG in a build, you'd know you were probably in for a bad time in an exciting new way.
If the API is clear and documented, I don't see why this would be an issue, except for the fact it might be a little bit clunky.
It's not the first solution I would come up with, but the question would be: why not? Just because we're used to older and more traditional patterns, why not just to embed webassembly for low level stuff in your code?
Absolutely no way is this a fine way to solve the problem. That is crazy talk.
1. It introduces additional toolchains into the solution when it is unnecessary.
2. It now means you need multiple language specialists to maintain it and associated communications and context switching.
3. More interfaces and integration means more fragility when it comes to debugging, problem solving as well as increasing the problem surface.
4. It massively increases the dependency stack which means there are now multiple sets of supply chain issues and patching required.
This makes no problems easier at all! It's even a bad last resort if that's all you have left to try.
Sound software architecture is very very well defined and this is definitely not it. I have seen entire companies burn by taking this approach to problem solving.
I'm really getting tired of solutions before problems and this is a fundamental example of it. Give us a real use case not manufacture a problem for it.
Sometimes you have that and you need to accept it. In this case the function was really trivial. What if it was a mega secret algorithm that needs Rust speed which you want to really write in Rust because XYZ? Or C++ I don't care. But not Go, which you want to use exclusively for microservices, for example.
> 3. More interfaces and integration means more fragility when it comes to debugging, problem solving as well as increasing the problem surface.
This is inevitable when you want to go that low level. Some companies use C++ for everything, some mix low/high level: how do you do in that case?
This article is about Go, but I could imagine something similar for Python: use something superfast under the hood, python for the high level part. It's really a common solution, which requires a bit of bindings left and right but it's worth it.
> 4. It massively increases the dependency stack which means there are now multiple sets of supply chain issues and patching required.
This is how software is done today. Maybe 30 years ago you would write everything in C and be happy with it. Today companies use at least 3 programming languages - at least that's my experience.
That's not a bad idea really, the wasm/wasi option could be a nice intermediate step between "we can't optimize the python any further" and "write a native extension" (or god forbid use cffi or the cursed horror that is ctypes).
I disagree. I see this in a similar way I see Electron and actually you can make the same arguments against using Electron.
But guess what, Electron wins on practicality. It makes creating GUI apps much easier. That wins over any problems associated with the extra baggage of shipping a whole browser. It doesn't win it for everyone, but it does for the majority of people who just want to get shit done.
The best kinds of hacks are the ones that look ludicrous but are actually somewhat fine in practice.
That is solved already and not what the article is about
The nonfunctional requirement is a self-contained binary that is not dependent on machine's own libraries or any extra files. That's not just mental excercise but a feature.
That is what article is about.
The "proper" engineering solution might be very well "just rewrite that small part in Go", but this approach is nonetheless interesting.
Let me add more to this: speed.
You have Rust/WebAsssembly in the mix and automatically you gain in speed as shown in the article.
I honestly don't understand the negative comments.
If you build a lib in C and then you use standard binding mechanisms, oh it's ok. In this case you leverage a great tool (cargo) to do the heavy lifting for you and bam you get a safe binary that gives you better performance and overall better tooling -> it's bad.... why?
I read the original version of the poster's comment and it was way more aggressive and more about "sound architecture". Maybe he/she can explain what exactly is wrong with this approach and what other approach should be taken instead?
> The "proper" engineering solution might be very well "just rewrite that small part in Go", but this approach is nonetheless interesting.
Why? In this case it's a trivial function. What if it's a strong algorithm that needs speed? Rust helps there, and it's faster than Go.
Because integrating anything in Go is such a pain in the ass gophers rewrite everything. Thus it makes perfect sense to a gopher.
wasm is not a javascript runtime.
> and accept a 10x performance decrease on runtime
Unless SIMD is involved (which is indeed a major issue around warm), the overhead of compiled wasm is generally observed below 50%, often closer to 15.
Obviously if you're using a wasm interpreter all bets are off.
The biggest roadblock at the moment is that Go WASM libraries are not in a very good state, except wazero. My assumption is that wazero will be slower than the cranelift-optimized wasmtime, etc. but I have not seen any benchmarks anywhere.
My impressions of the Go WASM libraries:
wazero: great Go-friendly API, not sure about performance, works on all OS (what the author chose)
wasmer: provides bare-minimum input and output for WASI, fast (it's what I chose for trealla-go). Doesn't work on Windows without significant pain, doesn't static compile the wasmer libraries so distribution is a pain. Seems essentially abandoned as its main contributor left the company.
wasmtime: basically impossible to get input and output in any reasonable way (unable to set stdin or read stdout; it can only inherit the FDs from the host), but might finally get buffers for I/O soon.
wasmedge: haven't investigated this yet, but it seems like it solves many of the problems above, promising
If anyone knows of a benchmark between these, I'd love to see it. I'm especially interested in wazero's execution speed. I think I'll try and run Trealla against it.
edit: I should also mention that wazero avoids the cgo overhead which could be a significant optimization for small functions as in this article, even if the runtime is slower. My use case is a long lived interpreter which is quite different.
wrt performance, we do watch it closely, but we've not done benchmarks vs non-default settings in other runtimes. It is the case that the tradeoff of avoiding dependencies means any optimizing JIT would have to be written to make long running things faster over time... no one has contributed this, yet, and more folks are looking at short lived despite it being the case interpreters are a great example of long lived.
Concretely, we do keep track of relative performance (literally each commit in fact), and it isn't uncommon to find PRs including perf before/after.
here are some pointers if interested in digging in! there are certainly some things we'd lose at.
https://github.com/tetratelabs/wazero/actions/runs/352306986... https://github.com/tetratelabs/wazero/tree/main/internal/int... https://github.com/tetratelabs/wazero/blob/main/Makefile#L32
Thanks for the analysis and good luck on things!
> doesn't static compile the wasmer libraries so distribution is a pain
I'll chat with the team to see what we can do about this!
These are the two issues I'm referring to:
It just keeps reminding me of the old rhyme about beans, beans, the magical fruit, the more you eat, the more you toot. (Although in the English of most former colonies that didn't violently rebel, it's pronounced "fart").
I suppose that's the point, it's a nice meta joke punning on tweet, but implying it's all just farting in the wind.
However it did amuse use that a man full of hot air would be named after the expelling of warm but noxious air.
So the more likely scenario is the name was only picked because it sounded similar to their original German family name while being an English-styled spelling.
Given we are taking 30+ years ago though, the best we can do at this stage is speculate.
However even if the card game theory were true, it still doesn’t make Trump a powerful name in the U.K. because the fart connotation is still more prevalent.
https://gizmodo.com/mastodon-toot-retired-twitter-tweet-equi...
As you've already done, you can call it a "message", I call it a "post". We don't need every social media site to strictly require their own bespoke terminology merely for the sake of branding.
Also true in American English. You have two things wrong:
1. The rhyme calls beans "the musical fruit".
2. "Toot" is relevant in that context, being a way you can describe blowing a horn.[1] But obviously, the primary reason for using the word "toot" there is that it rhymes with fruit, not that it's the normal word for farting.
[1] Or sometimes another instrument; there's a tongue twister that starts "A tutor who tooted the flute tried to tutor two tooters to toot."
And couldn't you have also saved a bunch of effort at the end by tweaking the rust program so that it wasn't just a one-and-done and only need one call to exec?
The current way, your go code starts a new system process to process every message, the way I'm suggesting it'll only start one for the whole run.
If you're interested, I'd suggest compiling a crate for WASI and seeing if you get compilation errors. You can do so by cross-compiling for the `wasm32-wasi` target (`rustup toolchain install wasm32-wasi`, then `cargo build --target wasm32-wasi`). If your program tries to use any stdlib facilities that don't exist on that target, it will tell you.
If you think I'm worth more, contact me with a job opportunity :)
Have a question: Isn't the wasm file compiled by rust already a binary? Why do we need to compile it first and then run it in the Go code?
Thanks!
The wazero library supports both of those options AFAIK.
> CPU can't execute WASM binaries
How was OP able to pipe the output of echo directly to the wasm binary initially?
> However this still depends on the program being compiled for your native OS and distribution as well as present in a folder in your $PATH.
Though it’s also possibly that the author has a wasm interpreter registered (or the wasm file has a shebang for one).
What. The actual. F.
How? Why? Who ever thought this was a good idea?
I would often complain about Twitter API, and how bad it was, but this is just beyond awful.
I guess it avoids needing to invent your own message format, but it means that every client needs an HTML parser in order to process and clean up statuses? That sounds... great.
Of course, I'm really hoping the HTML is added at runtime, and not stored in the DB. Imagine doing a data migration to modify an HTML stored in the DB.
C H A O S
Looks to me like HTML statuses are part of the federation protocol.
In fact, there's an issue[0] indicating that the sanitizer of the reference implementation doesn't allow Markdown to federate. There is also an old status indicating that even if more elements are added, the reference CSS basically strips everything (I assume visually)[1].
It's possible that their ads don't actually do any tracking, in which case they're receiving collateral damage. They seem technical enough, they should be able to figure out why the tracker blockers are blocking their ads and get things fixed (either in the ad code or in the upstream tracker blocker software).
Getting a few dollars here and there from a personal site's ads feels cheap and detracts from the article. Tip jar, fine. But ads no. It just feels dirty. Even if they are "ethical".
From my perspective (as an employer) I see this stuff and think holy hell they'll want to stick advertising on everything. Turns me right off.
From your perspective as an employer, this should signal that I know what I'm worth and I am more than willing to negotiate for it. If you want the ads gone, please feel free to email me a job opportunity. I'll be more than willing to seriously consider it should you meet my requirements.
How much does it cost to host that website? It can't be much more than 10-15 usd/month, right? If so, is it really worth it to recover such relatively small amounts through serving ads?
Maybe I'm wildly off in my estimation; personally I see adding ads as a pretty heavy thing to do, so the monetary benefits would have to clearly outweigh that...
The other expensive parts are AWS Route 53 for DNS after I dropped Cloudflare (cost varies based on popularity, but ranges between USD$7.50 and USD$12.50, this is still cheaper than Cloudflare because I paid them USD$20 per month) and the CDN I host on fly.io which costs about USD$5-7 per month including bandwidth overages.
My website gets more traffic than you are probably comfortable with imagining. I have to take performance and hardware efficiency seriously. I can easily do a few hundred gigabytes per month of egress bandwidth. More if I end up posting bangers. This is after doing things like hilariously optimizing images (the stickers can get down to about 10 KB each with avid files) and literally having my site load everything into ram on application boot.
I am told that these performance requirements are not needed for most websites, but I don't seem to be lucky enough to be able to do things the stupid way. I have to actually think about the performance impacts of everything I do because getting on the front page of Hacker News so often means that I need to focus on making things super efficient.
For a while my tower was also a Risen 5 3600, so I was doing the moral equivalent of compiling my website with -march=native to unlock _even more performance gains_, but now the machine I deploy from is a homelab node with an Intel Core i5 10600 so I can't do that trick anymore.
Subscribing to me on Patreon gives me infinitely more money than ads ever will, but having multiple income streams means that there's redundancy.
Of course I can afford to pay all of this out of pocket, but everything paying for itself is super fucking nice.
> also stores all of my random files I've accumulated over the years
> live backup of some very important files in case my house gets destroyed.
You should seriously consider moving your backups off your web server...
A) a very beefy machine and a lot of traffic,
B) a very detailed, thoughtful reply so thanks a lot for taking the time and
C) a wonderful explanation why your site loads so amazingly fast
I go into much more detail about this on my blog here:
- https://xeiaso.net/talks/how-my-website-works
- https://xeiaso.net/blog/xedn
- https://xeiaso.net/blog/site-update-mastodon-quoting
And pretty much in any post labeled "Site Update". My site is kind of hilariously complicated because it has to be. :(