1. 28
  1.  

  2. 16

    I submitted this because I want to show off something in particular: that async/await code that works in both evented I/O mode and normal (blocking) mode. This readme file explains it at the bottom of the “Performance” section.

    I think a lot of people have not realized yet that zig’s async/await is actually intended to be a high level “express the concurrency in your business logic” sort of thing, and I hope this can show it off a bit.

    Also is Zig noteworthy enough now to get its own lobste.rs tag? :-)

    1. 4

      I would think that would be decided by Zig users :). However I might caution you that most people use Tags as a filter rather than a search term, as searching for Zig is somewhat trivial (It’s not a particularly common word) but filtering out Zig requires a tag. It may be nice however if there were a tag for language discussions that are manual memory management or gc-lite like rust.

      1. 2

        Perhaps it’s because it’s late here, I’m tired, and I’m also getting a cold, but I’m not sure I get the point you’re trying to make here. Am I right to believe that this example throws shade to the famous node.js “factorial server” from years ago that showed computation kills an I/O based event loop, and that Zig doesn’t have this problem?

        And, as a follow up: is the reason for this that you’ve made the computation multiplication of 2 numbers, and then yield back to the event-loop for the next call up the stack?

        1. 1

          The point is that there’s no “async version” of the standard library, and when one makes a package in zig, they don’t have to choose whether to make an async version or not. You can write the same code, which expresses concurrency, but that works in applications that want to use evented I/O or blocking.

          1. 1

            no “async version” of the standard library, and when one makes a package in zig, they don’t have to choose whether to make an async version or not.

            Got it. This wasn’t something that I actually considered when reading this. Not sure why…

            1. 1

              Does that mean that the std lib will undergo asyncification?

              1. 2

                No, and that’s the point!

                You can write the same code, which expresses concurrency, but that works in applications that want to use evented I/O or blocking.

        2. 12

          Why is a Go version from 3 years ago used? What is the point of this comparison? If it is about performance then it is strange to use such an old version of one of the languages. If it is about source code comparison then what is the point of including the benchmarks? When I saw that Go from 3 years ago is used I initially suspected malicious intent and then I noticed that some of the Zig examples are calling C code for some reason. If there is some kind of a benchmark performed than the goal posts should be clearly defined and the methodology should be honest.

          1. 5
          2. 15

            The Zig gmp versions call C code, and are no longer really “Zig”, or a fair comparison to the Go code. You can use cgo to do the same with Go for an equal comparison.

            1. 7

              It looks like for the direct Zig vs Go comparisons, Go clearly wins. Now in full generosity to the author it appears they were trying to show how GMP versions are fast, but it’s unclear why that should be notable here.

              Compilation
              fact-linear.go - 0.11 seconds
              fact-linear.zig - 0.51 seconds
              
              fact-channel.go - 0.10 seconds
              fact-channel.zig - 1.0 seconds
              
              Performance
              fact-linear.go - 19.86 seconds
              fact-linear.zig - 46.43 seconds
              
              fact-channel.go - 20.2 seconds
              fact-channel.zig - 23.6 seconds
              
              1. 6

                it’s unclear why that should be notable here.

                Quoting the article:

                The most important thing to note here is that the fastest performance was a single-threaded implementation that linked gmp, which has high performance big-integer multiplication.

                So including gmp was a smart decision by Brendon to point out that hey, big caveat in this example, the bottleneck is large integer multiplication, and both Go and Zig’s std lib big ints are not even close to gmp’s performance.

                Which is why I’m trying to draw attention to the actual thing I’m trying to post about which is the fact-await.zig example demonstrating the same code working with evented I/O enabled and disabled. I think the significance of this has still not quite sunk in.

                1. 11

                  I think perhaps you might want to reword your article some to include some of these ideas a little more explicitly and perhaps redundantly, also earlier on in the article. If you wish to share effectively what you have done here, you have to word it in such a way that it gets received in the way that you expect. Test it out on some readers you can trust to be honest and direct. If you were trying to communicate that the bottleneck for both languages is a large integer multiplication that’s a fine and acceptable thing to say, but that wasn’t clear to me the reader. Certainly at a glance you can concede that it appears as though you’re comparing Go to Zig with GMP, as though Go can’t use GMP even though it can 1 .

                  [1] https://github.com/ncw/gmp

              2. 5

                GMP versions are clearly marked GMP and I don’t see anything unfair. I think if you send PR to add cgo/GMP version it will be accepted.

                1. 19

                  Just the three letters “gmp” don’t mean much; I had to look at the Zig source code to see it’s just calling C code; it could be a Zig library, for example. Right now someone looking at the overview will go away with the impression that Zig is significantly faster than Go, which is simply not the case.

                  I think if you send PR to add cgo/GMP version it will be accepted.

                  Probably, but I don’t think it’s my job to correct misleading benchmarks on the internet, and I don’t think that “send a PR” is a constructive reply to this kind of feedback.

                  1. 3

                    The article links to gmplib.org… You had to look at the Zig source code, but you could also have been an attentive reader. I tend to agree that the article could have been even more clear, and wording improvement also will be accepted with gratitude.

                    I don’t think that “send a PR” is a constructive reply to this kind of feedback.

                    Your “cgo” comment was clearly a feature request and not a bug report, and I believe “send a PR” is appropriate.

                    1. 13

                      I don’t know why you’re being so defensive; comparing a program with embed C versus one that doesn’t is clearly comparing apples to oranges. That it favours the language the author is trying to promote is not a good look, to say the least.

                      If you need to carefully read everything, follow links, and have knowledge of what certain three-letter acronyms are, then you’re just being misleading. It’s no different than starting a chart at non-0 to exaggerate trends, for example. Sure, the information is in there, but also easy to miss. Any casual reader – which are most readers – will take away that Zig is faster than Go, which is not demonstrated by this particular benchmark. This is rather interesting as the Zig’s homepage claims that “Zig is faster than C”.

              3. [Comment removed by author]

                1. 3

                  please leave me alone

                  1. [Comment removed by author]

                    1. 9

                      When some 1) ignores you and then 2) publically asks you to leave them alone, what do you think you should do?

                      1. 1

                        Isn’t HTTP client off-topic for Zig repository? That’s like filing curl bug to GCC Bugzilla and I wouldn’t be surprised if that results in a ban if repeated.

                        1. 2

                          I would say no, since the creator of the language himself posted it:

                          https://github.com/ziglang/zig/issues/2007

                          1. 7

                            @cup, please don’t flag stories and comments because you disagree with them. andrewrk’s comment asking to be left alone is not, in any sense, “incorrect”, and you’re flagging comments all over the place.

                        2. 1

                          Just use something like curl.