r/Zig • • 4h ago

Why is ZLS so dumb??

8 Upvotes

I know ZLS isn't expected to be an IDE level IntelliSense considering zig has many ambiguous features like anytype and such but shouldn't it still be able to atleast tell you when you forgot a try or catch, or like some other basic errors.

You shouldn't have to recompile every time to get error diagnosis, although I think zig's compilation speed does make it more bearable.


r/Zig • • 12h ago

[video] MicroZig - Compiling for tiny computers with Zig - Matthew Knight

Thumbnail youtube.com
17 Upvotes

The page with notes and links.

(at the bottom you’ll find a link to the source in case you’d like to make some changes to the page)

List of past and future Zig-related online events.


r/Zig • • 17h ago

simdjson-zig: simdjson bindings for Zig

Thumbnail github.com
18 Upvotes

simdjson-zig is a Zig package I've created that provides bindings to simdjson for Zig projects.

As far as I know, this is the first Zig binding to this library (previously some Zig ports existed). A few interesting things this library does:

  • Attempts to provide a drop-in replacement for std.json functionality like parseFromSlice(), parseFromTokenSource(), etc, to make it easy to swap in higher performance JSON parsing for existing code (at the expense of memory use). It was interesting to learn how these standard library APIs worked at a deeper level and to implement a performant backend that uses simdjson (I also had to learn a lot about how simdjson works).
  • Minimizes FFI overhead to improve performance by making a single parse call in C++ and passing back an internal format that I walk on the Zig side on demand. As long as I can emulate what std.json.Scanner does for each method call in my own TapeTokenSource type, I can substitute my own type and get the std library's "walk to fill out a struct" implementation for free, just providing tokens on demand as it asks for them.
  • Wraps C++, as simdjson doesn't provide a C interface. I wrote a C shim layer and used translate_c to access it from Zig.
  • Tons of unit tests and fuzzing to increase the quality and reduce the likelihood of regressions in the future.

Wishlist for future std library JSON implementations:

  • Allow token sources to provide already-parsed numbers instead of forcing them to pass strings (i.e. updating the grammar in https://ziglang.org/documentation/master/std/#std.json.Scanner.Token). simdjson parses numbers as part of its implementation, so having to re-stringify them just to pass them through to the Zig parser is inefficient and makes it hard to round-trip numbers correctly.
  • Make it possible to call into C code at comptime. I'm sure there are technical reasons this is not allowed, but it would be cool to parse JSON to structs at comptime using simdjson.

Open to questions or feedback about my use of Zig, simdjson, or anything else! I'm new to Zig so trying to learn as much as I can!