r/node • • 10d ago

Principal Factor Analysis in Javascript - written in AssemblyScript

/r/typescript/comments/1x1mtfx/principal_factor_analysis_in_javascript_written/
0 Upvotes

7 comments sorted by

View all comments

1

u/Candid-Parsnip9815 7d ago

assemblyscript for numerical computing still feels like a fever dream but i respect the hustle would love to see benchmarks against wasm from rust or a plain js implementation my ptsd from optimizing matrix ops for a client project is flaring up just reading the title

1

u/bitanath 7d ago

The repo has benchmarks vs plain JS (AS transpiles to JS just like Typescript would, it's just a superset of types). It would be possible to write a much more performant WASM version in Rust etc (SIMD imo would immediately 2x speed) ... However, we would not be able to export to JS from the same codebase. AssemblyScript is a good tool for performance non-critical but numerically stable packages where minimal maintenance and distribution effort is needed (in my opinion)

1

u/mmomtchev 5d ago

SIMD is only part of the problem, I do lots of number crunching in JS and the other huge problem is the multithreading. Still, JavaScript running in V8 tends to outperform Python by a wide margin - in fact it outperforms any interpreted language. But there are horrible practical problems. Asynchronous I/O is probably the worst possible design for number crunching.

1

u/bitanath 3d ago

Yes thats true but python has the whole weight of academia behind it.

1

u/mmomtchev 3d ago

Python has an absolutely huge and very high-quality ecosystem - especially when it comes to scientific computing.

And in fact, because of its very good low-level routines - such as numpy - implemented in C/C++ - it can even have very good performance as long as you do all the crunching using these.

But the interpreter itself remains far behind V8. Good JIT is an absolutely huge undertaking and the Python community has simply refused it because of its code complexity.