11

I am going to pass data up/down a 5-10 layered object using signals and slots. Which should result in a few thousand signal per sec. Which is far form "I clicked a button". All my object will also signal them self on a timer about every 100ms so they can do some processing.

What would be the fastest C++ Signal/Slot implementation which would be small and not require other library such as boost. (I need to keep the total size of my Binary very small).

I have seen libSigC++, sigSlot, Cpp-Events,

JP.
  • 495
  • 1
  • 9
  • 20

3 Answers3

6

How about Signals by pbhogan:

https://github.com/pbhogan/Signals

It's super fast (uses the FastDelegate code written by Don Clugston - also mentioned by Ismael), and it's pretty easy to use. I've been using it for some time now and had no problems.

sidewinderguy
  • 2,394
  • 4
  • 24
  • 24
  • 2
    not sure if this matters or not, but this implementation is not thread safe. – Eric Aug 15 '13 at 18:25
  • @Eric - that's true, more work would have to be expended to make a thread-safe version, and it might perform badly. – sidewinderguy Aug 15 '13 at 19:56
  • Not sure I follow you. If more work would be needed to make it thread safe then it's not thread safe.... I never stated it couldn't be made thread safe. I noticed this library from your post and when I looked at it, I was very discouraged by the nasty template and hackish Delegate class. Looks like a lot of voodoo at work to work around buggy compilers to get down to two lines of ASM. I'll play with it to see but this just screams debug nightmare to me. – Eric Aug 16 '13 at 13:52
  • @Eric Sorry for being unclear, I was agreeing with you that this library is most certainly not thread-safe. If you need a thread-safe signals library, then this one isn't for you I guess. I used this on a production product and I never had any problems at all. I agree it's kinda gross, and I expected lots of problems, but it went really smoothly. Thing is, it's dang fast. You sacrifice a few things to get that speed (namely it's syntactically not perfect). The thing is, the OP never required a thread-safe lib, so this was a valid answer. – sidewinderguy Aug 16 '13 at 17:39
  • @Eric - boost signals2 is a fully thread-safe signal/slot system which I've also used. It's pretty awesome, but it's less efficient than the minimal FastDelegate approach. – sidewinderguy Aug 16 '13 at 17:41
4

Often signal libraries are designed for ease of utilization, and not with a heavy performance in mind. You can check this article maybe helpful while pursuing fast execution.

In your case I'd start trying the more simple, like sigslot. But I'd not use a signal library under such circumstances... probably some kind of message queue, with a time stamp of some kind.

Ismael
  • 2,995
  • 29
  • 45
0

Even most complex and feature-rich signal/slot libraries are quite lightweight. The speed of signal emitting is in most cases comparable to virtual function call. In case of template-driven libraries such as boost::signals and libsigc++ you get essentially the same performance as you'd get passing function pointers around.

  • Invoking signals is only fast with libraries that aren't thread-safe. And I wouldn't entirely ignore connecting/disconnecting either, there are some libraries where those are rather expensive operations. – Paul Groke May 06 '11 at 22:57