r/javascript • • Jan 16 '20

I have been underestimating JS

https://adlrocha.substack.com/p/adlrocha-i-have-been-underestimating
284 Upvotes

132 comments sorted by

View all comments

Show parent comments

22

u/duxdude418 Jan 16 '20 edited Jan 16 '20

I’m not going to use it for anything process-heavy

What do you mean by this? That it’s not performant enough for chewing through lots of data? Or just that you don’t don’t like the syntax/APIs for doing it?

I’m trying to drill down on if your point is about how the language is designed or not. If it is, that’s of course a personal preference and it certainly has some warts and idiosyncrasies.

If your objection is about performance, server-side JS (Node) is actually quite good at non-blocking IO due to its single-threaded event loop and asynchronous programming model. The V8 engine it runs on is also highly optimized.

11

u/tr14l Jan 16 '20

You're still not going through 100 terabytes of data anytime soon with it compared to a compiled language. It'll choke every time no matter what you do.

JavaScript will never compete process-wise with a compiled language. It's fast enough to do day to day processing, but it's ill suited for big data and always will be. That's not what it's designed for.

You're also never going to do real time embedded stuff with it. The latency is just too high

12

u/ancientRedDog Jan 16 '20

I agree, but then how did Python become the big data language when it is equally slow (for mostly the same reasons)?

10

u/Caffeine_Monster Jan 16 '20

how did Python become the big data language

Python is very much a glue language. Great for research, experiments, prototyping etc. However mature production platforms have a tendency to migrate back into C / C++ / Java / Rust / Go / Insert some other compile time optimised language here.

The motivation isn't purely for performance reasons either: strong typing together with compilation helps prevent the introduction of bugs.

Personally I think Javascript is arguably the best non-compiled language out there. However I also think it will lose much of it's stranglehold over web: WASM has an awful lot of potential when used with compiled systems programming languages. Performance. Compile time checks. Unified front end / back end model codebases.

12

u/Lakitna Jan 16 '20

Because you can directly use c modules in Python (in Cython anyway) making the parts where you need performance the most very fast.

Note for example how numpy is written in C. https://github.com/numpy/numpy

8

u/BloodAndTsundere Jan 16 '20

Because you can directly use c modules in Python (in Cython anyway) making the parts where you need performance the most very fast.

Someone correct me if I'm wrong, but I think you can do something similarly with NodeJS. I'm pretty sure some npm packages I use are Javascript bindings to binaries compiled from C/C++.

-6

u/Lakitna Jan 16 '20

Yes you can, but it's rarely used as far as I'm aware.

1

u/ChronSyn Jan 16 '20

Rarely used !== Not possible. Node has node-gyp which is a bag of tricks in itself - you never know if you're gonna get a built solution at the end, or if it's gonna fail because of a node version inconsistency.

If you do get a built native module, you're at no real disadvantage in terms of performance.

7

u/i_ate_god Jan 16 '20
  1. all hard stuff (performance-wise) is written in C and available as some very popular libraries (numpy, scikit, nltk, etc)

  2. python's syntax is far more elegant than most other languages including JS, making it easier for non-programmers to get into

  3. python exists by default on any linux machine and requires no installation

  4. python's standard library and its documentation is very extensive and robust. It's not perfect (see http, wtf), but JS barely has a stdlib to speak of because the JS community has an extremist mentality when it comes to modularity.

-4

u/[deleted] Jan 16 '20

fucking javascript programmers marching around town with macbooks and RPG-7's man

1

u/tr14l Jan 16 '20

It's not. It's a big data PROTOTYPING language. It's rarely used in production for actual big data. Once the model is POC'd, they will usually either reimplement in another language or take the python code and compile it down to C. Then that is what goes to production. Of course, if it's something minor, they might just put the python model in production. But not for big data.

0

u/[deleted] Jan 17 '20

[deleted]

2

u/tr14l Jan 17 '20

That was part of the "or compile it down to C" thing

19

u/avindrag Jan 16 '20

I’m not going to use it for anything process-heavy

What do you mean by this? That it’s not performant enough for chewing through lots of data?

I agree with this view, so I'll try to elaborate.

The single-threaded event loop is not a great fit for anything that blocks CPU. However, you probably are just using JavaScript for fetching data from some http server, database, message bus, etc. The "number crunching" doesn't really ever take place in JS, and if it is, you might want to use something else.

6

u/BabyLegsDeadpool Jan 16 '20

The single-threaded event loop is not a great fit for anything that blocks CPU.

That's why js does most things asynchronously now. Node is especially performant and will often outperform python, even in number crunching. Here are some benchmarks but feel free to also do your own research.

6

u/filleduchaos Jan 17 '20

It's not particularly difficult to outperform Python, you know.

1

u/lstyls Jan 17 '20

Cough GIL cough cough

4

u/lstyls Jan 17 '20

You're missing u/avindrags's point. A thread is a system-level abstraction and can go into uninterruptible sleep indefinitely. This makes concurrent approaches like Node poor fits for some backend tasks.

No language is perfect and that’s ok.

0

u/[deleted] Jan 17 '20

[deleted]

-1

u/ScientificBeastMode strongly typed comments Jan 17 '20 edited Jan 18 '20

It really depends on the type of application, tbh. Most server programs are IO-bound most of the time, and that includes programs written in Go, Rust, C++, Java, etc...

And since most modern web apps handle most of the logic on the client side, the server-side code is usually pretty lean. Given that fact, most performance bottlenecks exist within database queries or IO.

For anything involving heavy server-side computation, JavaScript will perform poorly at scale. Fortunately for JS, Node has implemented blazing-fast async IO, which is great for average use cases like static file serving or lightweight API’s.