Skip to content

Decode single-item pointers, fix wide structs failing to compile - #3

Merged
lalinsky merged 2 commits into
mainfrom
bench-fixes
Oct 16, 2026
Merged

lalinsky merged 2 commits into
mainfrom
bench-fixes

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Two problems found while porting the twitter and canada schemas from serde-rs/json-benchmark.

Wide structs failed to compile

A struct with a few dozen fields and a jsonFormat failed with "evaluation exceeded 1000 backwards branches". The inline loops over a struct's fields run comptime code for every field (escaping its key, among other things), and all of it counts against the enclosing function's branch quota. twitter's User has 40 fields.

encodeStruct, encodeStructFieldsAfter, objectMembers and maxKeyLen now raise the quota in proportion to the fields and their name lengths, via fieldsBranchQuota.

*T could not be decoded

Encoding already dereferenced single-item pointers, but decoding hit @compileError. A *T is now allocated and decoded in place. That is what recursive types need: twitter's Status holds a retweeted_status: ?*Status.

Tests

Both cases have a test that fails without the fix: a 48-field struct with jsonFormat, and a recursive node type plus a bare *const u32. zig build test passes on 0.16 and 0.17.

Inline loops over a struct's fields count every comptime branch they
take, including escaping each key, against the enclosing function's
quota. A struct with a few dozen fields ran past the default 1000 and
failed to compile.
A *T is allocated and decoded in place, which is what recursive types
like a status that embeds another status need. Encoding already
dereferenced them.
@lalinsky
lalinsky added this pull request to stack #5 October 16, 2026 20:04
@lalinsky
lalinsky merged commit a2d2ab6 into main Oct 16, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant