You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When serializing Rust types to JSON, the Nones are serialized to JSON nulls. For example:
use cosmwasm_schema::cw_serde;use cosmwasm_std::to_json_string;#[cw_serde]structMyStruct{pubmaybe_string:Option<String>,}fnmain(){let my_struct = MyStruct{maybe_string:None,};println!("{}", to_json_string(&my_struct).unwrap());}
{"maybe_string":null}
This introduces some performance penalty. Since the Wasm host and the contract communicate data by loading serialized JSON strings into Wasm memory, having all the nulls means more data needs to be serialized and allocated into memory.
That would probably save small amounts of gas when transferring data from the contract into wasmd.
Wasmd / wasmvm charge 1 sdk gas unit per byte by default when deserializing json from the contract (can be changed by the chain, I believe).
I am a bit worried about the different ways different clients handle these things. For example a js client would then get undefined instead of null (probably not a huge problem in most cases, but could be one if it explicitly checks for === null).
I am also wondering: Does this impact the generated schema in some way?
When serializing Rust types to JSON, the
None
s are serialized to JSONnull
s. For example:This introduces some performance penalty. Since the Wasm host and the contract communicate data by loading serialized JSON strings into Wasm memory, having all the
null
s means more data needs to be serialized and allocated into memory.One way to avoid this is to use the
serde_with::skip_serializing_none
macro:We can consider incorporating this into
#[cw_serde]
, as well as adding it to all std library types.Not sure how much performance penalty there is for including all the
null
s or whether this improvement is worth it. Just a random thought.The text was updated successfully, but these errors were encountered: