Live data from Hacker News

Nodejs+Fabric as fast as multi-threaded C++

fabric-engine.com

11–20 of 68 posts

Re: Nodejs+Fabric as fast as multi-threaded C++

#12
post #6

Not that it diminishes the interestingness of this post (quite the opposite), but it's worth noting that this is not achieved using plain-vanilla JavaScript. From the product page: "The high-performance parts of the application are written using a performance-specific extension to JavaScript, called KL (Kernel Language). This language is similar in scope and syntax to JavaScript, but has some key differences that opt…

In other words, a better headline would be "Fabric Engine fast as multithreaded C++ (and can be glued to JS)"

And, apart from a stray use of new and delete, this looks almost like valid C99 code to me. Not that that diminishes the achievement any, of course. I'd quibble mildly about his choice of compile flags and make some minor stylistic changes to the code (like the tacky transpose :), but I don't think it would affect the benchmark results any.

Given the code used, it looks like it might be straightforward to use openmp rather than pthreads. I'd be interested in seeing how that works out.

Re: Nodejs+Fabric as fast as multi-threaded C++

#13

So this software involves installing a plugin in the browser? In an age where users are being warned by the browser makers themselves to be careful about that sort of thing? I can't see this ending well.

In this instance - since this is a node app - they are running the engine server side.

But yes, they do have a plugin version of Fabric. I have similar misgivings about that.

Re: Nodejs+Fabric as fast as multi-threaded C++

#14
Could probably squeeze a bit more out of the C++ version by targeting the specific architecture of the CPU to make use of SSE.

Also, what floating point type is KL using? float or double? - and is double necessary? - converting the C++ code to use floats would probably provide a fair speedup on the divides and due to squeezing more data into cache lines...

Re: Nodejs+Fabric as fast as multi-threaded C++

#15
post #4

The C++ versions were compiled using gcc version 4.4.5 using the compiler flags “-O6 – lpthread”. Isn't -O6 the same as -O3 ?

Yes it was a very WTF moment for me as well. The "C++" code is pretty much straight C, with references being the only C++ feature being used.

Re: Nodejs+Fabric as fast as multi-threaded C++

#16
post #11

I wouldn't call that code C++ at all, it's C with a few C++ keywords/niceties. [1],[2] [1] https://github.com/fabric-engine/Benchmarks/blob/f11cf6cc8cf... [2] https://github.com/fabric-engine/Benchmarks/blob/f11cf6cc8cf...

Yep and here is the C version: http://pastebin.com/z7apLBHb and it's diff: http://pastebin.com/YHjW6AHp

On my machine the C and C++ versions essentially have the same speed.

Re: Nodejs+Fabric as fast as multi-threaded C++

#17
post #14

Could probably squeeze a bit more out of the C++ version by targeting the specific architecture of the CPU to make use of SSE. Also, what floating point type is KL using? float or double? - and is double necessary? - converting the C++ code to use floats would probably provide a fair speedup on the divides and due to squeezing more data into cache lines...

Could probably squeeze a bit more out of the C++ version by targeting the specific architecture of the CPU to make use of SSE.

Not only that, from browsing the code, the critical loop is likely matrix multiplication. If that's the case, any kind of engine who is smart about SSE, cache lines, etc is going to be able to outperform simple C/C++ code.

Of course there's excellent matrix maths libraries for C/C++ that could be used instead.

Re: Nodejs+Fabric as fast as multi-threaded C++

#18

Not that it diminishes the interestingness of this post (quite the opposite), but it's worth noting that this is not achieved using plain-vanilla JavaScript. From the product page: "The high-performance parts of the application are written using a performance-specific extension to JavaScript, called KL (Kernel Language). This language is similar in scope and syntax to JavaScript, but has some key differences that opt…

I would agree. To me it looks they have made an easier way to create programs that process data in parallel efficiently and made it easy to use them from dynamic languages.

It's not so much "java script is as fast as C++", but "our system is a fast as C++ and you can use it from java script". They are using "Node.js" and "JavaScript" in title for the marketing angle if anything, because people don't use Node.js and JavaScript if they are trying to make parallel data processing programs.

Re: Nodejs+Fabric as fast as multi-threaded C++

#19
post #14

Could probably squeeze a bit more out of the C++ version by targeting the specific architecture of the CPU to make use of SSE. Also, what floating point type is KL using? float or double? - and is double necessary? - converting the C++ code to use floats would probably provide a fair speedup on the divides and due to squeezing more data into cache lines...

Actually seems like it doesn't...:

Using: -O3 -march=corei7 -msse -msse2 -msse3 -msse4 -fipa-matrix-reorg -fwhole-program

made negligible (if any) difference running var-mt:

Original: 30.464 30.211 30.646

with g++ options: 30.381 30.487 30.277

However, using ICC 12.0.4 (-o3 -xssse3) 25.418 25.613 25.392

On the same machine (SB 2.2Ghz).

Re: Nodejs+Fabric as fast as multi-threaded C++

#20

Not that it diminishes the interestingness of this post (quite the opposite), but it's worth noting that this is not achieved using plain-vanilla JavaScript. From the product page: "The high-performance parts of the application are written using a performance-specific extension to JavaScript, called KL (Kernel Language). This language is similar in scope and syntax to JavaScript, but has some key differences that opt…

It is something that JavaScript can never solve: Objects are objects, there has to be some constructs to make them work so it would never be as fast as C code.

The other blog post that appeared on HN this week sums it out [1].

For those who didn't read that post, basically, if you want the performance of C, you have to make those data as static and inflexible, i.e. use types and avoid indirection. Looking at the KL used in benchmark, you may find that it resembles C code. It's exactly what they did to make it fast: types and free from indirection.

[1]: http://blog.mrale.ph/post/12396216081/the-trap-of-the-perfor...

[2]: https://github.com/fabric-engine/Benchmarks/blob/master/Serv...

Post reply on HN