Shlemiel the Painter Is Back: How Zig’s libc Rewrite Made SQLite Slower

82 points by ohrv 20 hours ago on lobsters | 9 comments

squeek502 | 17 hours ago

Student | 18 hours ago

That’s a lovely way of explaining quadratic time operations. I took a quick look at the linked zig code, and presumably it’s like this because it’s mapping c strings into nice safe zig arrays rather than treating them as unsafe streams of memory locations containing chars.

refi64 | 18 hours ago

From one build and deploy script on my Mac I can target all of my platforms without containers or build machines. Zig’s elegant libzigc re-implements the standard library so you can static link the necessary functionality.

Zig uses musl (the standard library rewrite), but they have been rewriting it piece by piece in pure Zig (via libzigc), removing the C dependencies one at a time.

Hmm, was this using the musl triple when invoking zigbuild? I'd be a bit surprised if that didn't use musl, but I'm not sure what other libc values can be used in the triple other than glibc.

jdpage | 13 hours ago

Zig treats triples as requesting an ABI, rather than an implementation. A member of the core team discussed the rationale behind it in this Lobsters comment.

squeek502 | 16 hours ago

The quoted text is correct, you can follow the link to the commit and see that musl sources are deleted as libzigc symbols are added. This is also done for symbols provided by compiler_rt.

Relevant issues: https://github.com/ziglang/zig/issues/2879 -> https://codeberg.org/ziglang/zig/issues/30978

tobin_baker | 16 hours ago

Hate to say it, but LLM code review certainly would have caught such an obvious "accidentally quadratic" bug.

And we would have missed the community showing up, and having fun working together on a fix.

I think this is acceptable in a pre-1.0 language.

pmarreck | 10 hours ago

You don't even need that. You just need a ratio gate.

  1. Measure the time it takes for a function to process 1x an input (which is basically "setup time"), 10x an input, 100x an input, and 1000x an input. If you want to get fancy, warm it up first with 10000x input to get to steady-state performance.

  2. Measure the ratios between those times. (This should be somewhat cpu-details-orthogonal and somewhat immune to load effects.) Is it linear? n log n? n squared? Derive a complexity score from that (within a bit of tolerance). Force it to be under a certain score.

  3. Done.

mitsuhiko | an hour ago

But that is a lot more work than having an AI code reviewer run. And it only solves for a very narrow thing.