TL;DR After upgrading to shopify_function 1.1.1, we’re seeing 11% higher instruction counts when processing JSON metafields due to the required JsonValue
→ serde_json::Value
conversion.
Details
After upgrading shopify_function from 0.8.1 to 1.1.1 we are seeing a higher instruction count, specifically relating to complex cart operations.
Our Cart Transform function processes cart items with JSON metadata stored in metafields. After upgrading to take advantage of the new Wasm API, we’re seeing:
Performance Metrics:
-
Simple carts (1 item):
Improved (~3% reduction in instruction count)
-
Complex carts (items with large JSON structures):
Regression (~11% increase in instruction count)
-
Mixed carts:
Improved overall
Example measurements:
- Complex item on old version: 0.5285M instructions
- Same item on v1.1.1: 0.5892M instructions
This appears to stem from the change from serde_json::Value
to shopify_function::scalars::JsonValue
in the new API. We have had to convert JSON structures using our own json_value_to_serde() pattern, and it is computationally expensive, especially for deeply nested objects with many fields.
-
Are there recommended patterns for working with large JSON structures without converting to serde_json?
-
Is Shopify planning optimizations for JsonValue
or alternative approaches for complex JSON manipulation?
We’re concerned about scalability as our customers often have multiple complex items in their carts, and the instruction count scales linearly with complexity.
Any insights or recommended approaches would be greatly appreciated!
Thanks
Gabbie 
1 Like
In an ideal world, you want to remove serde_json completely from your function and pass the shopify_function library ALL the deserialisation work. You can do this by setting up the right key/value pair in custom_scalar_overrides
, in the typegen macro.
Hey thanks for the reply. I’ve worked on removing all serde from the function which looks like it has improved the instruction count, was just a big overhaul. I’m stuck on custom_scalar_overrides
, do you have an example of this that isn’t the Shopify doc for migrating to v1.0.0?
Am I correct in my understanding it would override all jsonValue types? I have multiple metafields so I’m not sure it can work for me?
*update - it doesn’t look like I can make use of custom_scalar_overrides
because our metafield is coming from a product in cart lines and it “can’t statically determine paths through arrays”
Thanks
Gabbie
We do take configuration from the product/merch level, and use custom_scalar_overrides.
It sounds like ‘Deserialize’ can’t be derived for your data type (by the shopify_function lib), although it’s hard to say without knowing the data structure.
Instead, you’d have to implement Deserialize trait provided by the shopify_function::wasm_api
namespace, something like:
use shopify_function::wasm_api::*;
impl Deserialize for MyConfigurationType {
fn deserialize(value: &Value) -> Result<Self, read::Error> {
}
}
This is really nice because now you get the lazy deserialization for your own configuration AND you can likely remove serde_json from your module!
Hope that helps!
Just got the lazy deserialization to work for our metafield on products! This was a huge win thanks for your help @bkspace! 
1 Like
Awesome, nice work! A bit fiddly, but well worth it!