3 ms·
I think the reason that the nesting level limit is 128 and the file size is 256 bytes for serde_json in this test is that the recursion_limit attribute is not c
by mojzu 7y ago
I think the reason that the nesting level limit is 128 and the file size is 256 bytes for serde_json in this test is that the recursion_limit attribute is not configured.
https://doc.rust-lang.org/reference/attributes/limits.html https://doc.rust-lang.org/reference/attributes/limits.html
The default value of this attribute is 128 which would explain both results, I'm guessing with configuration you could significantly increase both values at the expense of compilation time.
- edflsafoiewq 7y agoThat's for the recursion limit on compile time stuff, like how many layers of macros it will expand. serde does have this though: https://docs.rs/serde_json/1.0.41/serde_json/struct.Deserializer.html#method.disable_recursion_limit https://docs.rs/serde_json/1.0.41/serde_json/struct.Deserial...
- mojzu 7y agoFor some reason I thought serde was using macros to perform deserialisation. Now I know that isn't the case and it's a coincidence the default recursion limit and the serde default nesting limit is 128.
- lovasoa 7y agoEven if serde does indeed use macros, they run at compile time. The limit on macro recursion depth has an impact on what programs do compile, but it has no impact on the runtime behavior of these programs.
- eptcyka 7y agoThe recursion limit in the deserializer is a deliberate one https://github.com/serde-rs/json/pull/163 https://github.com/serde-rs/json/pull/163
- dmit 7y agoInterestingly, I recently encountered an issue in the wild where these two recursion limits are both prominently involved. Yew, the Wasm web framework, provides an html! macro that allows you to write templates that look like HTML within your Rust code. The macro is notorious for requiring the macro expansion `recursion_limit` to be raised even for fairly small templates. Now, if you happen to have a syntax error in a template and ask cargo to return the build errors as JSON, it will diligently report every macro expansion that led to the problem as a nested structure. Which is what the commonly used cargo-web tool does, so when it sees JSON with 128+ levels of macro expansion details describing a build error (again, not uncommon with Yew's html! macro), serde_json fails to parse it with `ErrorCode::RecursionLimitExceeded` and cargo-web panics. https://github.com/yewstack/yew/issues/661#issuecomment-546710072 https://github.com/yewstack/yew/issues/661#issuecomment-5467...