cinetec_tech Posted November 16, 2016 Posted November 16, 2016 we found vector is slow in unigine script. in init() put a 5000 items in vector forloop(int i=0;5000) vvtest.append(i); in update() try find a number not exist and loop 300 times per update` forloop(int i=0;300) int xx=vvtest.find(-1); on my computer it takes around 10ms for each update. is there any way to optimize the performance? thanks
maxi Posted November 23, 2016 Posted November 23, 2016 Hi, Unfortunately, this is not a vector issue. Unigine script stores data types in Variable class, and by obvious reasons it's operator== is not as fast as comparing pod types in c++. I suggest you to use a map in such cases. If this is impossible, you can optimize Variable::operator== in engine for needed data type, for example for integers add: int Variable::operator==(const Variable &v) const { if (type == 0 && v.type == 0) return (VARIABLE_INT_V == V_VARIABLE_INT_V); ... This speeds up your example by 2.5 times on my machine, but will slow down cases for other data types a bit.
cinetec_tech Posted November 23, 2016 Author Posted November 23, 2016 Hi, Unfortunately, this is not a vector issue. Unigine script stores data types in Variable class, and by obvious reasons it's operator== is not as fast as comparing pod types in c++. I suggest you to use a map in such cases. If this is impossible, you can optimize Variable::operator== in engine for needed data type, for example for integers add: int Variable::operator==(const Variable &v) const { if (type == 0 && v.type == 0) return (VARIABLE_INT_V == V_VARIABLE_INT_V); ... This speeds up your example by 2.5 times on my machine, but will slow down cases for other data types a bit. thanks Maxi. we will give a try.
Recommended Posts