[Bf-python] hints for optimizing python exporters, using Blender2Radiance for eg.
Willian Padovani Germano
wgermano at ig.com.br
Tue Mar 22 06:04:15 CET 2005
Campbell Barton wrote:
> (...)
> This can throw errors if the user has relitive paths in there
> filename.
> eg- an image filename may be //testures/myimage.png
>
> os.* functions dont understand blenders // as being the cerrent file
> dir in blender.
Yeah, stumbled upon it this weekend in a bad way (!), working on the
scripts registration code. Blender has a function to handle that
(BLI_convertstringcode). It's better to update all relevant places in
BPython to use this function before returning a path. Good catch, Campbell.
BTW, let me add two hints about optimization:
1) Profiling should not be underestimated. It'll tell you exactly where
you should attack to get better performance. And it can be as simple as
adding:
from Blender.Sys import time
oldtime = time()
# and in selected parts of the code, after each important section add:
newtime = Blender.sys.time()
print "some relevant string to tell you what piece was executed:",
print newtime - oldtime
oldtime = newtime
2) The ac3d exporter that will be in the next Blender got about 3 times
faster mostly because I changed all string concatenation operations to
faster alternatives:
# these are bad:
string1 = string1 + string2
string1 += string2
# this is faster:
string1 = "%s%s" % (string1, string2)
# this is very good:
l = []
l.append(string1)
# ... some operation to get another piece of the string
l.append(string2)
# ... some operation to get another piece of the string
l.append(string3)
# ...
# in the end use the string method str.join(sequence) to assemble the
string:
string = "".join(l)
# e.g. if you need separated text lines, use string = "\n".join(l) instead.
If you have lots of string concatenation in loops, this can really give
you a good speed gain.
--
Willian
More information about the Bf-python
mailing list