6 ms·
Zap – Fast backends in Zig
- idiomaticrust 3y agoFaster than axum? Nice!
- dralley 3y agoKeep in mind that microbenchmarks aren't necessarily representative of production performance. * Some webservers "cheat" and skip a lot of request headers which one may want to use in a production scenario to get better numbers. * Some web server architectures can do very well on many small uniformly sized requests but poorly on a mixture of request sizes. * Some web server architectures can get very good average latency but poor p99 latency. * Some benchmarking tools don't measure correctly: https://medium.com/@siddontang/the-coordinated-omission-problem-in-the-benchmark-tools-5d9abef79279 https://medium.com/@siddontang/the-coordinated-omission-prob... etc.
- giovannibonetti 3y agoThe benchmarks only include throughput, not latency (P50, P95, P99), which are quite important.
- AugustoCAS 3y agoIn what industries is Zig popular? I'm asking as I saw Zig as being the 'highest' paid language on the 2023 Stack Overflow Dev survey - https://survey.stackoverflow.co/2023/#section-salary-salary-and-experience-by-language https://survey.stackoverflow.co/2023/#section-salary-salary-... The performance looks outstanding!
- csjh 3y agoIt's still pretty early on, but it's aim is to be a C successor I believe. Main example of usage off the top of my head is for bun.sh
- itake 3y agohow is that different from rust? or is rust a cpp successor?
- r87 3y agoRust is more of a c++ successor, yes. It’s very much a kitchen sink language.
- seattle444 3y agoRust lives in the smart pointer world. So a good candidate as a c++ succesor. Zig lives in arena alloc and soa world. So it's a better than rust when you need performance beyond the norm.
- steveklabnik 3y agoJust to be clear, you can absolutely do arena allocation and soa in Rust.
- bvrmn 3y agoIn Rust you have convenient escape hatch with a default allocator. It's similar to say "you can do safe applications using C or C++".
- srgpqt 3y agoZig is still rather new, but it would be a good alternative to C, C++, Rust and Go.
- dontlaugh 3y agoThe first three, but not Go.
- IggleSniggle 3y agoWhy not Go? Not very comparable due to GC and goroutines?
- dontlaugh 3y agoRight. The others are system languages you could write a kernel or a game engine in.
- TwentyPosts 3y agoI'm going to be pedantic here, but this merely means that Go can't fill Zig's niche. Zig can (in a lot of situations) presumably easily fill Go's role. Both languages have a focus on simplicity and explicit syntax. In other words, Zig is in fact a decent alternative to Go. Go just isn't a good alternative to Zig.
- littlestymaar 3y agoZig isn't memory-safe, and you're not going to pay for the development overhead of manual memory management if you're doing regular back-end stuff.
- memefrog 3y agoPeople did for decades and a lot of that "regular back-end stuff" is in C++ at the moment. If you wanted to move it to a different language, you might currently choose to move it bit-by-bit to Go. But you could also move it bit-by-bit to Zig, and it wouldn't be an unreasonable choice. Zig is in that sense an alternative to Go, IMO.
- zengid 3y agoI was wondering this exact thing! Who's out there getting paid to write Zig?
- e4m2 3y agoThe core Zig devs, TigerBeetle and Bun are the main ones AFAIK. The latter two are VC backed, the Zig Software Foundation is a 501(c)(3).
- jedisct1 3y agoZig is very popular for WebAssembly: https://wasm4.org/blog/jam-2-results/ https://wasm4.org/blog/jam-2-results/
- Aransentin 3y agoMy company uses Zig to write software for small Linux devices, such as set-top boxes. The biggest benefit isn't exactly performance, but the absurdly tiny binaries it produces (very convenient if you are working with small flash disks!), and how the Zig standard library doesn't depend on anything other than the kernel, which means you can often entirely ignore all library issues; more often than not our software 'just works' when built for some new customer platform even though I've never even targeted that environment (or even CPU architecture) before.
- bryancoxwell 3y agoIf you don’t mind me asking, how long has your company been using Zig in production?
- Aransentin 3y agoWe first finished a Zig application three years ago, but that was a fairly small demo project which we didn't have to support afterwards.
- littlestymaar 3y ago> the performance looks outstanding! Well, given that in their benchmark Go ends up Boeing almost an order of magnitude raster than Rust, I wouldn't trust their benchmarking methodology too much.
- fransje26 3y agoWasn't Uber using Zig? At least for it's cross-compiler features, if I recall properly.
- jedisct1 3y agoYes, Uber use Zig: https://www.uber.com/en-FR/blog/bootstrapping-ubers-infrastructure-on-arm64-with-zig/ https://www.uber.com/en-FR/blog/bootstrapping-ubers-infrastr...
- generichuman 3y agoWraps the C library https://facil.io/ https://facil.io/. I hope they port it & go pure Zig at some point.
- detrites 3y agoAre there advantages to this other than, I guess it being convenient? (Zig noob here.) Eg, are there C to Zig ports that have had a demonstrable performance or memory-safety gain or something like that? (Specifically, I mean over a C-lib wrapper compiled using Zig, as matching this case.)
- jedisct1 3y agoThe Zig compiler itself is a good example: https://kristoff.it/blog/zig-self-hosted-now-what/ https://kristoff.it/blog/zig-self-hosted-now-what/ "The new self-hosted compiler reduces memory usage 3x compared to the old C++ implementation"
- dangets 3y agoHave to point out that this includes second system optimizations. Just porting C over to Zig won't give you that 3x reduction. For others, I also highly recommend the video linked in that blog post.
- yakkityyak 3y ago[flagged]
- von_lohengramm 3y agoThe lightning bolt emoji and similar performance rhetoric is really popular in the Zig community. I doubt the similarity is intentional.
- slimsag 3y agoI think you mean zap-the-golang-logger conflicts with OWASP's ZAP, which was started in 2011 before the-golang-logger.
- dvaun 3y agoIt’d be fun to see a component system name as a play on words based on the theater game zip-zap-zop.
- beanjuiceII 3y agoI'll just say it: there's always that person who has to come in and tell people how a projects name is named the same as some random thing in the universe, then scours the internets playing the "when was it first created" game. I'd say no one cares, but then there's 'that person' who clearly does! weird.
- yakaccount4 3y agoI don't particularly care, but it's lazy. It's nicer if people try and pick something unique and unambiguous in the domain, so searches don't clash. Obviously, that's not always possible, but in this case, I'm not giving them the benefit of the doubt.
- ledgerdev 3y agoSeeing this, and the use of zig for https://github.com/tigerbeetledb/tigerbeetle https://github.com/tigerbeetledb/tigerbeetle I wonder if zig might become a good tradeoff vs rust for servers if in long term it's more readable and maintainable and with a different approach to quality. I would also be interested to hear the compile time, binary size and memory usage of those example apps. Looks like the underlying facil.io library hasn't seen any commits since 2021, so that's a bit of a red flag. https://github.com/boazsegev/facil.io https://github.com/boazsegev/facil.io
- jorangreef 3y agoThanks, we did a podcast interview this past Sunday on TigerBeetle, also looking at safety as a philosophy (beyond what any language can provide), that I hope you enjoy: https://www.youtube.com/watch?v=0pHHb6ONTbw https://www.youtube.com/watch?v=0pHHb6ONTbw
- Thaxll 3y agoDoes Zap add the datetime in every http response as header because Go does it and those are syscalls so it reduces performance.
- fluffyspork 3y agoNice to see someone else thinks about this. In my personal project webserver I don't. I didn't measure, but just trying not to do unnecessary work.
- memefrog 3y agoThat shouldn't reduce performance too much, right? Getting the current time is such a frequently-executed system call that, as far as I understand, its implementation is in a vDSO in Linux that is loaded into every process. This means you shouldn't need the full cost of a system call when you get the current time.
- faraggi 3y agoWhat a wasted opportunity to call it zag.
- ARandomerDude 3y agoZap sounds fast and active, which is definitely a goal of the project. Zag sounds like it's inefficient.
- Solvency 3y agoRust sounds like something old and crusty. No one will ever adopt a language called Ru...
- ARandomerDude 3y ago> Rust sounds like something old and crusty. True > No one will ever adopt a language called Ru... I never made this claim.
- deleted 3y ago[deleted]
- corentin88 3y agoHow does it compete with Node.js? The benchmark (req/s) compares Zap with Rust, Go, etc. But I don't see any mention of Node.js.
- giovannibonetti 3y agoNode.js should be way slower, given that JS is an interpreted language and the others aren't.
- jedisct1 3y agoNot really. All modern JS engines, including V8 that Node uses, include excellent JIT compilers. Also, HTTP serving in Node uses code written in C, not JS. That being said, Node is slow compared to Bun: https://bun.sh https://bun.sh
- winrid 3y agoAt the expense of memory usage, predictibility, and worse P99s.
- adamrezich 3y agowow, I had not heard of facil.io (the thing this is based on)—I'll have to give both of these a look, as I'm working on something conceptually similar. neat!
- jedisct1 3y agoFacebook's Proxygen is also pretty neat: https://github.com/facebook/proxygen https://github.com/facebook/proxygen
- adamrezich 3y agointeresting! I was looking for stuff like this awhile back when I started my project and couldn't find anything—I probably was using the wrong search terms. my goal is to create a simple web framework that produces a single compiled executable, but I don't want to care too much about the HTTP(S) server portion, if possible. I have a functioning prototype, but the wrote-it-myself-and-it-shows HTTP server part sucks, so, hopefully I can find something to replace it with, instead of diving deep and writing something like this on my own.
- andrewmatte 3y agoCongratulations! This is really great. I am going to try it. In your benchmarks, consider adding actix which is also in Rust but considerably faster than rust axum according to: https://www.techempower.com/benchmarks/#section=data-r21&test=composite&l=yyksn3-6bj https://www.techempower.com/benchmarks/#section=data-r21&tes...
- andrewmatte 3y agoThere might also be a chance you can have your webserver included in the techempower benchmarks for their next round. Their code is submitted by experts and open-source: https://github.com/TechEmpower/FrameworkBenchmarks https://github.com/TechEmpower/FrameworkBenchmarks
- dralley 3y agoTechempower benchmarks are not a good measure of real-world performance. Everyone cheats on them, they don't do a great job of matching realistic workloads, and there's plenty of unresolved issues filed about methodology problems. Actix also used to be the poster child for overly focusing on benchmark performance at the expense of real world concerns.
- LAC-Tech 3y agoVery cool - this is a big missing piece in the zig ecosystem. Wish the project all the best.
- pjmlp 3y agoAre they also blazingly fast producing CVEs? Given the current state of use-after-free and similar issues.