Porting Go's strings package to C(antonz.org)

60 points | by ingve 3 days ago

3 comments

  • johaugum 20 minutes ago
    On index benchmark results:

    >Still not quite as fast as Go, but it's close. Honestly, I don't know why the memchr-based implementation is still slower than Go's assembly here, but I decided not to pursue it any further.

    Libc call overhead. Your version is using an already-fast memchr, but it still has to cross a general libc boundary and then do the pointer/index around it.

    Index with a 1-byte needle collapses to IndexByte, and on arm64 that goes into Go asm.

  • nasretdinov 3 days ago
    Interestingly enough, the initial Go implementation was indeed just a transpiler to C, and generally Go and C are semantically very similar. So the fact that you can even (successfully and relatively easily) do Go->C transpiling isn't entirely surprising. Of course you can't port `go` keyword and GC, but the language that the author is developing (called So) doesn't support these features anyway :).
    • pram 4 hours ago
      Early Go was the first time I ever saw the Plan 9 compiler/linker used in action:

      https://9p.io/sys/doc/compiler.html

    • dimes 4 hours ago
      I could be wrong, but I don't think the initial Go implementation was a C transpiler. It was written in C, but it did its own compilation.
    • throwaway27448 2 hours ago
      Alef is the missing link between C and Go.
  • welder 5 hours ago
    Refreshing seeing someone coding without AI in 2026.