Slow Tag Write Performance

I have a script that iterates through 20 system.tag.writeAll functions, sort of like what follows. It’s only writing five values at a time, but the script takes about XX seconds to complete, which seems really excessive. Am I doing something wrong? Is there a faster way to accomplish this?

x = 0
while x <=19:
val1 = somevalue
val2 = somevalue
val3 = somevalue
val4 = somevalue
val5 = somevalue

 tag1 = "prefix_" + str(x) + "_suffix1"
 tag2 = "prefix_" + str(x) + "_suffix2"
 tag3 = "prefix_" + str(x) + "_suffix3"
 tag4 = "prefix_" + str(x) + "_suffix4"
 tag5 = "prefix_" + str(x) + "_suffix5"

 vals = [val1,val2,val3,val4,val5]
 tags = [tag1,tag2,tag3,tag4,tag5]

 system.tag.writeAll(tags,vals)

 x = x + 1

What if you called system.tag.writeAll a single time for all tags, instead of calling it 20 times?

That might be a lot faster.

I’ll give it a shot. Unfortunately it means that the code will be 20 times longer to allow for all the variable assignments.

Use a loop to create a list of all your tags, and a list of all your values. Then call system.tag.writeAll once.

I did as you suggested, and have much better results. Thanks very much for your help. I didn’t know about the list.extend() function, and that was very helpful in accomplishing this.

You should not need to call extend() explicitly. Try the following.

vals = []
tags = []
for x in range(20):
    val1 = somevalue
    val2 = somevalue 
    val3 = somevalue
    val4 = somevalue
    val5 = somevalue
 
    vals += [val1,val2,val3,val4,val5]
    tags += ["prefix_%d_suffix%d"%(x,i) for i in range(5)]  #This creates an in place list for us, and appends it to the main list

system.tag.writeAll(tags,vals)