simd-lite / simd-json-derive

high performance Serialize and Deserialize derives

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add skip_serializing_if support

Licenser opened this issue · comments

add #[serde(skip_serializing_if = "Option::is_none")] support

Hey @Licenser is there a workaround to this for now? I have a couple structs that have bunch of optional fields that I would love to skip serializing. Right now I've been duplicating structs without a field but this doesn't scale well.

Sadly there is no workaround, it'd need to be implemented. it'd need to be properly implemented. It shouldn't be extensively hard but some work that requires time.

Gotcha. Is this something you have plans to implement in the near future. If not that's totally cool, I can work with duplicate structs for now :)

I took a short look at it this weekend it's not quite straightforward to implement without losing the optimisations done for writing.

The biggest thing is that before writing simd-json-derive precomputes the name of to escape and add control characters this works if we know all fields are present, it gets more complicated if we don't we basically need to move some of the logic to runtime at this point and avoid moving all of it there if not needed. The same logic is applied in other places too.

I'd like to add it but I'm not sure when I get the time, I'll open a draft PR non the less with including the attribute and some placeholder start in case someone wants to pick it up in the meantime and drive it home.

Understood, thank you so much @Licenser :)

Heya,

I implemented the needed code in #64 since there might be a bunch of corner cases and I don't have an active use-case could you give the branch a try and see if it works for you? If yes I'll merge and release this

Hey! Yep I can do that now, I'll test it against a couple APIs that I'm working with

Yep, not only does it totally work in my case, but you just helped me shave ~10 KB off my WASM binary from deduplicating models. That's fantastic!

Thanks so much for this @Licenser, you're the best ✋

sweet :D I'm glad to hear that, the code isn't super optimized but I guess it's good enough ™️ for now

released as 0.11.3

sweet!