Migrating to shopify_function 1.1.1 - instruction count increase

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 JsonValueserde_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): :white_check_mark: Improved (~3% reduction in instruction count)

  • Complex carts (items with large JSON structures): :cross_mark: Regression (~11% increase in instruction count)

  • Mixed carts: :white_check_mark: 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.

  1. Are there recommended patterns for working with large JSON structures without converting to serde_json?

  2. 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 :slight_smile:

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.