OMNeT++/OMNEST Bug Tracker - OMNeT++
View Issue Details
0000022OMNeT++simulation kernelpublic2008-12-05 16:112009-07-25 17:38
0000022: Perfomance issue: cMessage::getArrivalTime() returns simtime_t by value
cMessage::getArrivalTime() returns simtime_t by value. This is a performance problem especially for the FES (shiftup and insert).

After changing the method to return const simtime_t& we had performance improvements of about 10-20 percent (compiled with -O3).

Probably this should be changed for all simtime_t setters and getters in cmessage.h.
No tags attached.
diff simtime_by_reference.diff (941) 2009-03-10 12:03
Issue History
2008-12-05 16:11baumgartNew Issue
2009-03-10 12:03baumgartFile Added: simtime_by_reference.diff
2009-07-25 13:22andrasNote Added: 0000160
2009-07-25 13:23andrasAssigned To => andras
2009-07-25 13:23andrasStatusnew => in work
2009-07-25 13:24andrasNote Edited: 0000160
2009-07-25 17:38andrasNote Added: 0000161
2009-07-25 17:38andrasStatusin work => resolved
2009-07-25 17:38andrasFixed in Version => 4.1
2009-07-25 17:38andrasResolutionopen => fixed

2009-07-25 13:22   
(edited on: 2009-07-25 13:24)
I did some measurements as well, with interesting results.

cqn example (100 tandems, 50 queues/tandem), cmdenv express mode, ubuntu 32-bit, g++ 4.3.2.

In debug mode (make MODE=debug), I saw the performance hit you described (~ 15-20% spent in getArrivalTime()).

In release builds (-O2), this difference disappeared:

  real 0m15.372s
  user 0m10.257s
  sys 0m0.144s

  real 0m15.377s
  user 0m10.193s
  sys 0m0.124s

kcachegrind runs showed similar results (difference was only ~0.2%).

Still, going on with the change looks like a good idea, because debug builds benefit a lot.

It is an interesting question how this would affect performance on 64-bit architectures, where a SimTime object fits into a single machine register. There, returning a reference (which is actually a pointer) instead of the value might be a performance penalty. I did not make measurements in this direction yet. However, today most users are still on 32-bit architectures, so the change would benefit them.

2009-07-25 17:38   
Introduced simtime_t_retval which is a typedef for const simtime_t&, and changed cMessage method return types to that. Via simtime_t_retval, it will be easy to turn off this optimization when it adversely affects performance (i.e. 64-bit optimized builds)