Cart Transform - Instruction Count Limit Exceeded Error

Hello,

I’m seeing a large number of InstructionCountLimitExceededError failures on our cart transform function of late, they appear to be caused by unrealistically large carts, potentially created by bots.

Just curious how I could go about addressing these?

Cheers!

Simon.

@simon_b I think it is because of the Cloudflare Bot. That is the classic bot-abouse pattern hitting a Cloudflare Worker instruction limit.

Ah right, thanks @Andrii_Hudimov is there anything that can be done or do we just ignore it?

Just returning { operations: [] } (a no-op) for oversized carts is the right call
It’s harmless for real customers and keeps you under the instruction limit. Don’t ignore it entirely since the errors will keep accumulating, but the early exit guard is a one-liner fix you can ship right now.

Yeah so something like this I assume:

if (input.cart.lines.length > X) return { operations: [] };

But where to draw the line…

I think for my function at least it appears to breakdown around 165 line items

There can be carts up to 500 cart lines (generally for large B2B stores). It’s up to you weather you service those customers or not. Early returning is not a real solution, although it may quiet down the errors!

The best thing you can do is:

a.) Decide if you want your function to handle large carts or not.
b.) Optimise your WASM instruction count.
c.) Make sure you track your performance using GitHub - Shopify/shopify-function-test-helpers: Package containing helpers for wasm-level testing of shopify functions · GitHub

For (b), there isn’t one right answer. You might need to improve the algorithmic complexity of your function, or perhaps switching to a Rust toolchain (or other) that has better performance overall might work.

Okay thanks for the tips @bkspace, much appreciated.

For my app’s context and what I use the transform for I think it’s fine to use the guard for now. But if I see genuine orders coming through with 165+ line items I’ll look at optimising my WASM instruction count to see if I can squeeze more out of the function.

Switching to Rust is also likely a good idea.

Thanks heaps!

Simon.