Most active commenters
  • pjmlp(3)

←back to thread

153 points yar-kravtsov | 12 comments | | HN request time: 0.2s | source | bottom

I built a Vite plugin that lets you write Go code directly in .js files using a "use golang" directive. It compiles to WebAssembly automatically.
1. pjmlp ◴[] No.45718527[source]
Cool hack, just use JavaScript.
replies(2): >>45718573 #>>45718617 #
2. kitd ◴[] No.45718573[source]
The author explains why you might want to use Go instead at the end of the readme.
replies(1): >>45718644 #
3. Cthulhu_ ◴[] No.45718617[source]
99 times out of a hundred, sure. But sometimes you need better performance or a library that isn't available in JS.
replies(3): >>45718843 #>>45718863 #>>45720349 #
4. onion2k ◴[] No.45718644[source]
I don't think any of the use cases suggested really make sense though. For a compute-intense task like audio or video processing, or for scientific computing where there's likely to be a requirement to fetch a ton of data, the browser is the wrong place to do that work. Build a frontend and make an API that runs on a server somewhere.

As for cryptography, trusting that the WASM build of your preferred library hasn't introduced any problems demonstrates a level of risk tolerance that far exceeds what most people working in cryptography would accept. Besides, browsers have quite good cryptographic APIs built in. :)

replies(2): >>45718737 #>>45718926 #
5. tgv ◴[] No.45718737{3}[source]
> For a compute-intense task

The browser often runs on an immensely powerful computer. It's a waste to use that power only for a dumb terminal. As a matter of fact, my laptop is 6 years old by now, and considerably faster than the VPS on which our backend runs.

I let the browser do things such as data summarizing/charting, and image convolution (in Javascript!). I'm also considering harnassing it for video pre-processing.

replies(1): >>45718847 #
6. pjmlp ◴[] No.45718843[source]
WebGPU or WebGL is the answer.
replies(1): >>45720060 #
7. pjmlp ◴[] No.45718847{4}[source]
You can take advantage of that power via WebGPU, or WebGL if the browser is not yet up to it.
8. hollowturtle ◴[] No.45718863[source]
Better performance? For javascript code that calls into native platform apis provided by the browser it's been alteady proven that performance is an order of magnitude better than calling into wasm and doing all the sheningans to move bytes from and to wasm
9. preommr ◴[] No.45718926{3}[source]
> For a compute-intense task like audio or video processing, or for scientific computing where there's likely to be a requirement to fetch a ton of data, the browser is the wrong place to do that work.

... I mean... elaborate?

Everytime I've heard somebody say this, it's always a form of someone stuck in the 90s/00s where they have this notion that browsers showing gifs is the ceiling and that real work can only happen on the server.

Idk how common this is now, but a a few years ago (~2017) people would show projects like figma tha drew a few hundred things on screen and people would be amazed. Which is crazy, because things like webgl, wasm, webrtc, webaudio are insanely powerful apis that give pretty low level access. A somewhat related idea are people that keep clamoring for dom access in wasm because, again, people have this idea that web = webpage/dom, but that's a segway into a whole other thing.

replies(1): >>45719930 #
10. chrisweekly ◴[] No.45719930{4}[source]
great points, agreed

also "segway" is a scooter, "segue" is a narrative transition

11. dgb23 ◴[] No.45720060{3}[source]
I second that, having just relatively recently used the native browser APis for image processing. While it felt a bit awkward to use, it served its purpose pretty well.

If I needed more, I would probably not use Go anyways, but a sharper tool instead.

12. ramses0 ◴[] No.45720349[source]
Or even "use server.physics.go", which is where my mind went to (and where I've messed around with language interoperability with tinygo before).

This is such a wonderfully blursed and "smooth" implementation!