getty-zig/getty

Do not assume deserialized `struct` keys are allocated

Closed this issue · 0 comments

Currently, Getty assumes that all deserialized pointers are allocated. Initially, I felt that this assumption was a reasonable one to make, is consistent, and made Deserializer and Visitor implementations simple.

The issue, however, is that not all deserialized pointers are part of the value produced by a Visitor. For example, during struct deserialization, deserialized keys (i.e., slices) are used only to check against a struct's field name. The key isn't a part of the final struct value at all. In such cases, allocating the key is not only pointless, it's terrible for performance.

The current solution around this is to, in the deserializer implementation, provide a custom deserialization block for struct values. But that's a lot of work that will have to be repeated across libraries and it doesn't change the fact that the default behavior for struct deserialization is slow.

So, I propose that Getty should assume that all deserialized pointers are allocated except during struct key deserialization (struct value deserialization will still assume that pointers are allocated). This will make Deserializer implementations better and faster, and Visitor impls can still be kept simple.