I am using Python and I have a recursive function that takes a huge list as one of the arguments:
# Current implementation
def MyFunction(arg1, arg2, my_huge_list)
...
...
MyFunction(new_arg1, new_arg2, my_huge_list)
As you can see above, MyFunction
is called recursively using the same list my_huge_list
; this doesn't change, unlike the other arguments. And, again, this list is huge. A friend of mine suggested that I could treat my_huge_list
as a global variable to improve the performance, as otherwise this huge list may be copied over and over in every iteration.
# Friend's suggestion
MyHugeList=[a,b,c, ...and many many other elements... ]
def MyFunction(arg1, arg2)
global MyHugeList
...
...
MyFunction(new_arg1, new_arg2)
Does using a global variable as shown above improve the performance of the algorithm over the original version? My program runs for weeks, so even a slight improvement may be valuable in the long run.