High performance C++11 signals

Overview

High performance C++11 signals

See Performance of a C++11 Signal System for the original source code, as well as performance measurements compared to other signalling systems.

The original author, Tim Janik, licensed the source code to the public domain CC0 1.0 Universal (CC0 1.0).

Declare a signal

This example declares a signal 'sig' that takes three arguments and returns a char.

Simple::Signal<char (float, int, std::string)> sig;

Connect to a signal

This example connects 'sig' to a static function. It is also possible to connect to member functions or lambda functions.

static char float_callback (float f, int, std::string) {
  // ...
  return 0;
}

void Init() {
  sig.connect(float_callback);
}

Fire a signal

void func() {
  // ...
  sig.emit(1.0f, 7, "xxxx");
}
Issues
  • replaced the linked ring with reference count with simple std::list and std::shared_ptr

    replaced the linked ring with reference count with simple std::list and std::shared_ptr

    I don't understand why a handmade linked list/ring was used here, with manual reference count. Don't we have std::list and std::shared_ptr for this kind of job? Can some one explain to me the rationale behind that?

    I change the linked list to std::list, and the reference counting logic to std::shared_ptr, it passed the test cases. Because of the std::list overhead, now per emission size is 24 bytes compare to 8 bytes, I suppose when more slots are connected, the difference will be smaller. On my Mac, the peak memory used by the master implementation and my version are almost the same, 892928 vs 901120.

    But surprisingly, the latency of my version is much smaller, on my 2013 Mac pro, with 3.5 GHz 6-Core Intel Xeon E5, the master implementation took 22.417022ns per emission. My version only took 4.695005ns.

    > time -l ./test.master
    Signal/Basic Tests: OK
    Signal/CollectorVector: OK
    Signal/CollectorUntil0: OK
    Signal/CollectorWhile0: OK
    Signal/Benchmark: Simple::Signal: OK
      Benchmark: Simple::Signal: 22.417022ns per emission (size=8): OK
    Signal/Benchmark: callback loop: OK
      Benchmark: callback loop: 0.014000ns per round: OK
            0.02 real         0.02 user         0.00 sys
        892928  maximum resident set size
             0  average shared memory size
             0  average unshared data size
             0  average unshared stack size
           221  page reclaims
             9  page faults
             0  swaps
             0  block input operations
             0  block output operations
             0  messages sent
             0  messages received
             0  signals received
             1  voluntary context switches
             8  involuntary context switches
    
    > time -l ./test.list
    Signal/Basic Tests: OK
    Signal/CollectorVector: OK
    Signal/CollectorUntil0: OK
    Signal/CollectorWhile0: OK
    Signal/Benchmark: Simple::Signal: OK
      Benchmark: Simple::Signal: 4.695005ns per emission (size=24): OK
    Signal/Benchmark: callback loop: OK
      Benchmark: callback loop: 0.001000ns per round: OK
            0.01 real         0.00 user         0.00 sys
        901120  maximum resident set size
             0  average shared memory size
             0  average unshared data size
             0  average unshared stack size
           221  page reclaims
            11  page faults
             0  swaps
             0  block input operations
             0  block output operations
             0  messages sent
             0  messages received
             0  signals received
             1  voluntary context switches
             5  involuntary context switches
    
    opened by leira 2
  • Removed unused, wrong code

    Removed unused, wrong code

    The member method SignalLink::deactivate is currently unused and can be safely removed.

    Moreover, it has a subtle issue: the comparison cbf == function wouldn't work in any case. That's because the two variables are of type CbFunction, that is std::function<R (Args...)> and the operator== for them is defined to check only with nullptr. In other terms, a std::function can be compared with nullptr, but it cannot be compared with another std::function, as from the standard.

    Fortunately, everything compiles fine because it is part of a template class and, being that function not used, it is not considered by the compiler. You can easily test it by invoking the function somewhere: you won't get an error at runtime, while you will get an error at compile time saying that you cannot compare two functions.

    opened by skypjack 2
  • Make the emit function const

    Make the emit function const

    for SimpleSignal.h

    • make invoke const as well since emit calls it
    • remove commented out includes
    • add missing header

    for test.cpp

    • add
    • minimal changes to support microsoft compiler
    opened by tnovotny 1
  • -fsanitize indicates minor memory leak with size()

    -fsanitize indicates minor memory leak with size()

    compile with -fsanitize=address to note small leak when using size(); fixed by adding a decref() call at the end of the while loop when calculating size

    opened by chocolatemelt 1
  • suppress annoying errors

    suppress annoying errors

    As suggested within the file test.cpp, one should use the following line to compile it:

    g++ -Wall -O2 -std=gnu++11 -pthread test.cpp && ./a.out
    

    Anyway, on some systems it results in the following annoying error:

    test.cpp: In function ‘void bench_simple_signal()’: test.cpp:179:33: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]

    An explicit cast will suppress that warning.

    opened by skypjack 1
Owner
Lars Pensjö
Lars Pensjö
The movements of your RC vehicles are jerky and not smooth? This Arduino device will solve this issue by adding acceleration and deceleration ramps to the PWM signals!

This is an Arduino Pro Mini 3.3V / 8MHz based RC servo ramp / delay generator Features: 4 RC servo PWM inputs and outputs (can be enhanced) Reads the

null 4 Apr 15, 2022
Shell program written in C to implement various system calls, with support of executing commands, output redirection and signals.

Use ./shell command to start the shell. $<space>path/executable to run the executable(please specify the path without beginning it with "/"). Eg. type

Ayuj Panchal 1 Nov 15, 2021
Small data exchange program using UNIX signals.

Small data exchange program using UNIX signals.

Maria Sottomayor 30 May 20, 2022
A small data exchange program using UNIX signals.

minitalk The purpose of this project is to code a small data exchange program using UNIX signals. Thanks to 0x00Jeff for the great help ❤️ . What is s

Jakom 10 Jun 1, 2022
An eventing framework for building high performance and high scalability systems in C.

NOTE: THIS PROJECT HAS BEEN DEPRECATED AND IS NO LONGER ACTIVELY MAINTAINED As of 2019-03-08, this project will no longer be maintained and will be ar

Meta Archive 1.7k Jun 15, 2022
A C++11 large integer library with effective high performance, simplistic in nature and also clean in the eyes.

BigIntegerCPP BigIntegerCPP is a C++11 port of large integer library used in CryptoLib4Pascal. It allows mostly parsing of numbers as strings in diffe

Telepati 25 Apr 22, 2022
High Performance Streams Based on Coroutine TS ⚡

Conduit ⚡ Lazy High Performance Streams using Coroutine TS Conduit is a utility library for building and transforming, ranges and lazy (infinite) iter

LoopPerfect 141 Apr 29, 2022
high performance C++20 implementation of std::variant

A minimal compile-time overhead, C++20 implementation of std::variant. Fully standard conforming with a couple of documented differences.

null 26 Apr 13, 2022
Convenient, high-performance RGB color and position control for console output

Oof (omnipotent output friend) It's common for C++ programs to write output to the console. But consoles are far more capable than what they are usual

Sebastian Werhausen 739 Jun 21, 2022
PHP Encoder, protect PHP scripts in PHP 8 and PHP 7, High Performance, Compitable with X86_64, MIPS, ARM platform and Ubuntu/Centos/OpenWRT system.

What's FRICC2? FRICC2 is a PHP Script encryption tool. When you are developing a commercial software using PHP, the script can be distributed as encry

Hoowa Sun 29 May 19, 2022
Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.

The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text. Diff: Compare two blocks o

Google 5.4k Jun 27, 2022
Flexible, portable, high-performance bit fields C++ library. unsigned a:13 becomes F<13> a;

C-plus-plus-library-bit-fields Flexible, portible, high-performance bit fields C++ library. The bit fields are specified with a dummy structure where

Walt Karas 25 Feb 27, 2022
Real Time, High performance BOT detection and protection

REAL-TIME BOT PROTECTION CHALLENGE IronFox https://innovera.ir IronFox is a real-time and high performance bot protection, that using Nginx as a reve

Khalegh Salehi 3 Jun 5, 2022
Cloud-native high-performance edge/middle/service proxy

Cloud-native high-performance edge/middle/service proxy Envoy is hosted by the Cloud Native Computing Foundation (CNCF). If you are a company that wan

Envoy Proxy - CNCF 19.9k Jun 25, 2022
Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64).

HPC Emerg Emergency alert and tracer for realtime high-performance computing app (work in progress, currently supported env is only Linux x86-64). Exa

Ammar Faizi 7 Jan 19, 2022
Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on OpenGL 1.x-4.x supporting Windows, Linux and Mac OS X.

Visualization Library 2.2 Gallery About Visualization Library is a C++ middleware for high-performance 2D and 3D graphics applications based on the in

Michele 293 Jun 26, 2022
A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store

SimDB A high performance, shared memory, lock free, cross platform, single file, no dependencies, C++11 key-value store. SimDB is part of LAVA (Live A

null 442 Jun 25, 2022
A high-performance MongoDB driver for C

mongo-c-driver About mongo-c-driver is a project that includes two libraries: libmongoc, a client library written in C for MongoDB. libbson, a library

mongodb 731 Jun 30, 2022
Kit: a magical, high performance programming language, designed for game development

Kit: a magical, high performance programming language, designed for game development

Kit Programming Language 990 Jun 25, 2022