mmomtchev/igc-xc-score

[Question] Perfomance

Closed this issue · 3 comments

vicb commented

Hey Momtchil,

Do you have any idea on how this code perform vs a C implementation of the same algo ?

I'd like to integrate igc-xc-score with flyxc in the coming months.

As part of that I'm interested in how a node C-extension would perform and also how WASM would perform.

Would be great if you have some insights - if not I'll try to keep with issue updated with my findings.

Thanks

WASM won't be faster for sure.

C++ could be marginally faster, but the real benefit will be portability and multithreading. The algorithm used is naturally parallel and igc-xc-score cannot take advantage of it because of the lack of good shared memory data structures - especially R-Trees - in Node.js.

I did briefly consider creating a C++ version - not because it is faster - but because it could be embedded on a flight computer. However the development of my affair caught up with the flight instrument manufacturers.

If you can find all the base components - I think that boost has everything but the packed Hilbert R-Trees - there should probably be about 2 weeks of work.

vicb commented

Thanks for the insight.

Do you think it would be a lot of work to implement this shared data structure in JS (using SharedArrayBuffer/Atomics)?

One benefit I see with C/C++ code is also that it would easily transpile to WASM meaning that we could have support for browser + node for free (including multi-threading).

I'll work more on that in a few weeks and will keep this updated.

Sure, you could, but frankly WASM is still somewhat rough on the edges - no one uses WASM when there is a JS version.

Making a packed Hilbert R-Tree in a SharedArrayBuffer that supports concurrent access is a project that is slightly larger than igc-xc-score itself with an end result that will probably have no other uses.

The latest version can process even the most complex flights in under 1 minute, which is about ok, and given my precarious current standing with the paragliding community - I would prefer to see where my affair is going before investing large amounts of time in this project.

Maybe there could be an intermediate solution that supports only back-end processing in Node.js and uses shared data structures from C++/boost. This could probably be made to work in a week of hard work or so. Especially if NAPI supports is finally added to SWIG - which is probably a much better use of my time. Not that my current standing with the Node.js core team is any different - but simply because it is a much more needed project. Once this is done, a partially C++, partially JS parallel version of igc-xc-score will be much easier to make.

I do not remember who said it, but I always found it right on the target: V8 is a C++ engine that you can pilot by using JavaScript.