Are there any problems with repeating proxyActivities calls in a loop?

Let’s say I am writing a helper function to use across workflows, and the helper function calls a couple of activities. Some parent workflows might loop through a medium-sized array (e.g. 100-300 items) and call the helper function on every iteration. I think I have three options to work with:

  1. The helper function uses proxyActivities to get the activity functions it needs. This provides nice encapsulation: the parent workflow doesn’t have to know or care what activities the helper uses.
  2. The helper function expects the parent workflow to run proxyActivities for the two that it requires, then pass those functions in as arguments. This would mitigate any problems with the helper calling proxyActivities on every loop iteration.
  3. Turn the helper function into a child workflow. Then it has no choice but to call proxyActivities itself.

Assuming I have no other reason to think the helper needs to be a child workflow, option (1) is definitely the simplest. But I’m wondering if there are any problems with repeating proxyActivities calls in this way. So I’m wondering what you would recommend.

I’m using the TypeScript SDK, in case that affects the answer.

1 Like

Calling proxyActivities is fairly cheap and there shouldn’t be any noticeable impact for calling it repeatedly.

The cost is just a creation of a JS Proxy object and validation of the activity options: sdk-typescript/packages/workflow/src/workflow.ts at d77c3c26cb3d7e051119a1234b5e876393fd5504 · temporalio/sdk-typescript · GitHub

1 Like