What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

InstructionCountLimitExceededError in Product Discount Function API

InstructionCountLimitExceededError in Product Discount Function API

temurbek
Shopify Partner
24 0 2

It says in docs: 

`InstructionCountLimitExceededError: Shopify stopped the function after it exceeded the maximum instruction count of 11 million instructions.`

 

But it needs to be clarified what the actual cost 1 instruction is.

If I declare a variable does it cost 1 instruction? Or If there is 1 loop, does it cost 1 instruction?


This error is occurring in one store but users add less than 10 products to their cart
How is it possible to return this error?


 

Replies 3 (3)

Nick_Wesselman
Shopify Staff
171 43 73

Hi @temurbek --

An instruction is a WebAssembly instruction. You can't measure this by looking at your source code directly. However you can use Shopify CLI to execute your function locally and measure it. You can use standard language tools to measure and optimize the performance of your code.

 

There are cases with large orders that may be difficult to handle with Functions today. We have plans to address this. But 10 products should be manageable. Do you have a very large amount of data (e.g. metafields) being returned with each product? Or are you writing console logs on every loop through the cart potentially?

 

-Nick

 

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

temurbek
Shopify Partner
24 0 2

Hello, Thank you for your response
Yes, I measured the instructions with Shopify CLI and it turns out that our Product Discount Function can handle approximately 150-180 line items
I think this amount is not bad, but our function is failing with one store even every hour

are there any other reasons for this error?

Thank you

Nick_Wesselman
Shopify Staff
171 43 73

Can you request the merchant share the error logs so that you can test your performance with those specific inputs?

Nick Wesselman | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog