Tuesday, April 7, 2015

Workers, speech recognition and Concept 4.1

Concept 4.1 brings new optimizations, starting with recursive calls (around 50% more efficient), less memory usage for class objects ( - 50%), memory pools for objects, and workers - efficient threads that can be used by the standard Concept Core (no need to use the inefficient multi-threaded core).

Speed and memory optimizations

When testing using the binary tree benchmark (found here: http://benchmarksgame.alioth.debian.org/u64/program.php?test=binarytrees&lang=yarv, and here: http://benchmarksgame.alioth.debian.org/u64/program.php?test=binarytrees&lang=php)

PHP 5.6: Memory used - 369M to 1200M - 345 seconds
Concept 4.1: 79M to 269M - 170 seconds
Ruby 2.2.1: 176M constant - 87 seconds

Ruby is faster on this benchmark only, because it excludes the Concept JIT, how ever, when the JIT is active (ex: mathematical functions and/or loops, based on the Sieve benchmark, concept is about 20 times faster than PHP).

For the fannkuch redux benchmark (foudn here: http://benchmarksgame.alioth.debian.org/u64/program.php?test=fannkuchredux&lang=yarv)

Ruby:

Pfannkuchen(11) = 51
Time: 87435 ms

Concept:
Pfannkuchen(11) = 51
Time: 40401 ms

Ruby seems faster than Concept only on recursive calls, but I'm working on that. On the fannkuchen benchmark, Concept is more than 2x faster.

On Sieve benchmark, Concept scores 8040 iterations/second, while V8 scores on the same machine about 20000, but it uses far more memory. For now, I think that Concept has the optimal balance between speed and memory usage.

Concept Workers

When dealing with multit-hreaded applications, Concept MT core is significantly slower compared to the standard core. This is because it uses a global semaphore for synchronizing threads. The best alternative were the green threads, which are cheap, fast and don't need synchronization. The main drawback is that a blocking call, will block all the green threads. The alternative is the use of a worker.

A worker is a thread that runs in a different context, and exchange data via various APIs with the main thread.

Consider the following example:

Notice that the ChildWorker constructor simply waits for data (via Worker::Pending) and notifies the result via Worker::Result. I was inspired by the javascript web workers, with one exception: the worker runs in the same application (no need for external files).

Speech recognition

Concept 4.1 brings a wrapper for the pocketsphinx library. To see it in action, check the speech recognition example here.

As usual, lots of bugs are now fixed, new APIs for SIP protocol and DTMF, and a more advanced profiler, capable of showing the memory usage,



No comments: