4 ms·
It's a powerful alternative to Rust and C++ for writing ultra low latency code when safety isn't important, like games or HFT. Its standard library and ecosyste
by logicchains 1y ago
It's a powerful alternative to Rust and C++ for writing ultra low latency code when safety isn't important, like games or HFT. Its standard library and ecosystem have excellent support for passing around allocators and no hidden dynamic allocation (every function that allocates takes an allocator as a parameter), which makes it much harder to hit the latency pitfalls common to Rust and C++. It also encourages the latency-optimal approach of using local bump-a-pointer arena allocators where possible rather than the slow global allocator. And finally, the superior metaprogramming support makes it more convenient to use high performance techniques like struct-of-arrays.
- lossolo 1y agoYour comment was corrected or written by ChatGPT, right? It's super interesting that I can recognize these things now. The specific usage of punctuation, certain words and sentence construction.
- pclmulqdq 1y agoRusty rust and C++-y C++ are both often slower than hand-rolled C for a given function, and zig is intended to be a better way to hand-roll some C. C as a language is obsessed with the fact that C runs everywhere. Even on a DSP with a 24-bit char and a 24-bit int. If you take out those complexities and you add 40 years of lessons on language design, you can make something a lot simpler.
- metaltyphoon 1y ago> Rusty rust and C++-y C++ are both often slower than hand-rolled C for a given function This makes no sense whatsoever and very far from the truth.
- Arch-TK 1y agoRusty rust? I don't think there is such a specific thing and certainly disagree that all idiomatic rust is somehow slower by default. You can write rust like you might write a higher level language and then that can end up slower but if you write idiomatic low level rust, the performance is much harder to compare with C. There are things which will be faster in C and things which will be faster in Rust but broadly things will be extremely similar in performance. I write bare metal embedded rust a lot these days and there are quite complex concepts you can represent in rust which make your code a lot safer without a performance hit.
- pclmulqdq 1y agoIdiomatic "low level" rust clocks in at about 10-50% slower than hand-coded C every time I try it. It is also about 10x easier to write the Rust code. Unsafe is just required a lot of the time. Sometimes it's code size or struct size just being larger to express a similar concept. To get back your performance you have to do things that are un-idiomatic (but you have to do in C anyway).
- Arch-TK 1y agoShow examples please.
- simonask 1y agoThat is an unbelievable claim. 1. Rust structs are generally smaller due to layout optimization. 2. A 10-50% difference is well within the “are you measuring debug builds?” territory. I’m curious what code you are writing that requires unsafe all the time? I do a lot of low-level optimization, and unsafe is barely ever actually needed.
- pclmulqdq 1y agoIt sounds like you work with people who don't really know C. Understanding how to pack a struct is a pretty basic skill. Write an optimized database or network stack without unsafe for me. https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-gcc.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- speed_spread 1y agoSafety not important in HFT? You'd better make sure those precious microseconds buy you enough to make up for when things go awry. Also, modern online gaming with microtransactions isn't something I'd entrust to "hold my beer" languages and gaming industry development practices.
- Cloudef 1y ago> modern online gaming with microtransactions I don't think anyone should develop such games either
- logicchains 1y ago>Safety not important in HFT? You'd better make sure those precious microseconds buy you enough to make up for when things go awry. Memory safety bugs are very rare in modern, well-written and tested C++. The key difference is that there are no adversarial inputs, while something like a browser or server needs to deal with potentially adversarial inputs, making absolute memory safety much more important (as even a single memory safety issue could be exploited).
- clanky 1y agoCrashes from safety bugs are rare in HFT because they can replay years of data against code changes. For a strategy that trades in and out of positions quickly and is flat most of the time, it's also often not a big deal if the program crashes in the midst of running, as long as some technique has been arranged to cancel resting orders and alert a trader (who is generally monitoring the system's operations at all times). They're certainly not inclined to pursue safety at any expense of performance in their code.
- Validark 1y ago"Safety" is always important, and you can write safe software in Zig.
- simonask 1y ago“Safety” as defined in the context of the Rust language - the absence of Undefined Behavior - is important 100% of the time. Without it, you are not writing programs in the language you think you are using. That’s a convoluted way to say that UB is much, much worse than you think. A C program with UB is not a C program, but something else.
- kiitos 1y agocurious, where is the definition of "undefined behavior" for rust specified?
- simonask 1y agoHere: https://doc.rust-lang.org/reference/behavior-considered-undefined.html https://doc.rust-lang.org/reference/behavior-considered-unde...
- kiitos 1y agommm, no, that's an explicitly incomplete list of informally-described observable behaviors that qualify as undefined -- which is fine and good! but quite far from a specification!