GlobalEventSet::fireEvent performance
Posted: Fri Feb 10, 2012 21:57
We've been spending some time optimizing our engine's performance. Using Intel's sampling profiler, we found that GlobalEventSet::fireEvent is the fourth biggest hotspot in our engine. After some investigation, it turns out that the cost of this function is in the string concatenation that builds the event name.
I'm not sure if this effects everyone (we have a lot of windows), but it seems like there might be some merit to refactoring things to remove the per-event string concatenation. Off the top of my head, I see three ways it could be done.
1) Modify EventSet::fireEvent to take the event name and global event name. This would require a second static string constant for all event names. A set of macros could be used to always declare and define both event names. The advantage of this, is that it has a very low runtime cost. The disadvantage is that its either tedious, or uses macros.
2) The implementation of GlobalEventSet could change, to store events in a manner that didn't require a string concatenation to find them. For example a std::map<std::pair<String, String>, Event*>. This has the advantage of not changing the interface to the event system. The downside is that it requires some duplication of code that already exists in EventSet, and is not quite as efficient as the previous method.
3) The implementation of EventSet is modified to support two string keys (as in #2 above), and the existing method implementations pass in the empty namespace string. The advantage is that GlobalEventSet doesn't have to duplicate as much EventSet code, and the existing interface doesn't change. The downside is that it probably adds overhead to non-global events.
What do you guys think? Is there a better solution?
--Thanks
I'm not sure if this effects everyone (we have a lot of windows), but it seems like there might be some merit to refactoring things to remove the per-event string concatenation. Off the top of my head, I see three ways it could be done.
1) Modify EventSet::fireEvent to take the event name and global event name. This would require a second static string constant for all event names. A set of macros could be used to always declare and define both event names. The advantage of this, is that it has a very low runtime cost. The disadvantage is that its either tedious, or uses macros.
2) The implementation of GlobalEventSet could change, to store events in a manner that didn't require a string concatenation to find them. For example a std::map<std::pair<String, String>, Event*>. This has the advantage of not changing the interface to the event system. The downside is that it requires some duplication of code that already exists in EventSet, and is not quite as efficient as the previous method.
3) The implementation of EventSet is modified to support two string keys (as in #2 above), and the existing method implementations pass in the empty namespace string. The advantage is that GlobalEventSet doesn't have to duplicate as much EventSet code, and the existing interface doesn't change. The downside is that it probably adds overhead to non-global events.
What do you guys think? Is there a better solution?
--Thanks