If you're not sure why your task script might be slow, enable Liquid profiling. This feature times the execution of each Liquid statement, giving you insight into where your task is spending more or less time.
The Liquid profiling option can be found in the task's advanced settings:
Clicking here reveals the option itself:
Check the box, and save the task. Subsequent runs of the task will include a new section at the end of their results, labeled "Liquid performance profile":
Each object in the profile includes three attributes:
"render_time" (measured in seconds). Liquid nodes that have children also have a
"children" attribute, containing an array of timing objects for each child node.