Live data from Hacker News

How I turned Zig into my favorite language to write network programs in

lalinsky.com

21–30 of 150 posts

Re: How I turned Zig into my favorite language to write network programs in

#21

> Context switching is virtually free, comparable to a function call. If you’re counting that low, then you need to count carefully. A coroutine switch, however well implemented, inevitably breaks the branch predictor’s idea of your return stack, but the effect of mispredicted returns will be smeared over the target coroutine’s execution rather than concentrated at the point of the switch. (Similar issues exist with…

> I’m actually not sure if Zig’s async design even uses hardware call/return pairs

Zig no longer has async in the language (and hasn't for quite some time). The OP implemented task switching in user-space.

Re: How I turned Zig into my favorite language to write network programs in

#23

What makes a NATS client implementation the right prototype from which to extract a generic async framework layer? This looks interesting but I'm not familiar with NATS

The layer was not extracted from the NATS client, the NATS client was just a source of frustration that prompted this creation.

Re: How I turned Zig into my favorite language to write network programs in

#25

Earlier quoted context omitted.

only for hobby project

You or in general? Because, you know, this is like, your opinion, man.

My Opinion???

how about you goes to Zig github and check how progress of the language

it literally there and its still beta test and not fit for production let alone have mature ecosystem

Re: How I turned Zig into my favorite language to write network programs in

#26

> Context switching is virtually free, comparable to a function call. If you’re counting that low, then you need to count carefully. A coroutine switch, however well implemented, inevitably breaks the branch predictor’s idea of your return stack, but the effect of mispredicted returns will be smeared over the target coroutine’s execution rather than concentrated at the point of the switch. (Similar issues exist with…

You are right that the statement was overblown, however when I was testing with "trivial" load between yields (synchronized ping-pong between coroutines), I was getting numbers that I had trouble believing, when comparing them to other solutions.

Re: How I turned Zig into my favorite language to write network programs in

#27
post #20

I really need to play with Zig. I got really into Rust a few months ago, and I was actually extremely impressed by Tokio, so if this library also gives me Go-style concurrency without having to rely on a garbage collector, then I am likely to enjoy it.

Go has tricks that you can't replicate elsewhere, things like infinitely growable stacks, that's only possible thanks to the garbage collector. But I did enjoy working on this, I'm continually impressed with Zig for how nice high-level looking APIs are possible in such a low-level language.

Re: How I turned Zig into my favorite language to write network programs in

#28
post #18

Earlier quoted context omitted.

TigerBeetle, Bun, and Ghostty all beg to differ...

[flagged]

Bun is 100% fine in production. And you should be using it instead of transpiling TypeScript unless there’s some other barrier to using it.

Re: How I turned Zig into my favorite language to write network programs in

#30
I am still mystified as to why callback-based async seems to have become the standard. What this and e.g. libtask[1] do seems so much cleaner to me.

The Rust folks adopted async with callbacks, and they were essentially starting from scratch so had no need to do it that way, and they are smarter than I (both individually and collectively) so I'm sure they have a reason; I just don't know what it is.

1: https://swtch.com/libtask/

Post reply on HN