I was testing out a new BH config I made that was quite complex and noticed that holding ALT would significantly drop the frame rate. I profiled the code and found the source of the problem to be excessive reallocation calls within the Rule::Evaluate function.
After some investigation, this was because the conditionStack vector was defined locally in the Evaluate() function. So each time Evaluate() was called, the conditionStack would have to be reallocated. Not only that, but it would potentially have to be dynamically resized as push_back() was called, and it also had to be deleted at the end of the function.
I moved the conditionStack to a struct member and use the resize(0) method to clear the contents without forcing reallocation. This seems to have given a pretty substantial performance gain. I don't really see the frame rate drop anymore. I also see that the operator delete[] call is no longer present in the call stack (was previously very high % exclusive).
Someone might want to check the size I initially reserve for conditionStack in case it's too large. Also, I think it might be a good idea to move Rule::Evaluate definition to the cpp file.
I was testing out a new BH config I made that was quite complex and noticed that holding ALT would significantly drop the frame rate. I profiled the code and found the source of the problem to be excessive reallocation calls within the Rule::Evaluate function.
After some investigation, this was because the conditionStack vector was defined locally in the Evaluate() function. So each time Evaluate() was called, the conditionStack would have to be reallocated. Not only that, but it would potentially have to be dynamically resized as push_back() was called, and it also had to be deleted at the end of the function.
I moved the conditionStack to a struct member and use the resize(0) method to clear the contents without forcing reallocation. This seems to have given a pretty substantial performance gain. I don't really see the frame rate drop anymore. I also see that the operator delete[] call is no longer present in the call stack (was previously very high % exclusive).
Someone might want to check the size I initially reserve for conditionStack in case it's too large. Also, I think it might be a good idea to move Rule::Evaluate definition to the cpp file.
Before:
After:
Sleepy files: BH_profiling.zip