Best practice reading tags in a loop

Hi!

I have a script similar to this (don't take literally the script is just an example):

objects = []  # list of objects
for obj in objects:
    tag = system.tag.readBlocking([obj.get("fullPath")])

    # do something

    results.append()

return results

However, I'm wondering if it would be better to read all tags at the same time and then process them.

objects = []  # list of objects
paths = []

for obj in objects:
    paths.append(obj.get("fullPath"))

tags = system.tag.readBlocking(paths)

for t in tags:

    # do something

    results.append()

return results

Note that the object list could be about 1000+ items long depending on the plant.
What do you think?

Yes! Bulk reading the tags is much better than reading single tag at a time.

This is an understatement! You should never read individual tag paths in a loop. It can and will significantly slow down your script, particularly with higher tag counts, not to mention put additional load on the gateway

Yup. And if you're doing it because you need to read a couple different tags from different areas over and over, learn about zip() and how you can use it with multiple lists generated from bulk reads.