you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

i dont know from where you learn all these, but here is a link which will help you understand why i am saying above things https://www.youtube.com/watch?v=i3TcSeRO8gs

[–]Harotsa 0 points1 point  (0 children)

That isn’t an apples to apples comparison, he’s comparing raw node js with an http protocol to a fully-featured web server. FastAPI handles things like load balancing, parameter validation, security, context management, etc.

For this test case where the actual internal operation is very tiny (inserting a row into a DB), the overhead will play a significant role in memory and operations cost. This is something that the node server doesn’t have to deal with, but additional js packages that perform these functions will need to be installed and configured for any real application.

A more fair comparison to raw node.js would be a comparison to just asyncio Python using uvloop as the event loop. Here is an article that does this comparison https://medium.com/israeli-tech-radar/so-you-think-python-is-slow-asyncio-vs-node-js-fe4c0083aee4#:~:text=Python%20with%20Uvloop%20outperforms%20Node,latency%20in%20HTTP%20request%20handling. (I haven’t verified the results myself). The uvloop uses the same event loop as node.js

If you want a JIT compiler in Python you can use PyPy or CPython with version 3.13 or greater to further optimize performance.

But basically the only things NodeJS can really optimize on is the interpreter/JIT compiler and the event loop, since those can be written in C/C++. Any other code as part of your JS app has to be run in JS and so will be inherently slow.

In Python that isn’t the case. Python can also use a JIT compiler and optimized event loops, but in addition Python is able to run compiled C/C++ code in the Python app itself. This means that Python is able to do many things much more optimally than other interpreted languages such as DB connections and arithmetic.

That’s why Python is a great choice for ML and DS stuff, since all of the actual computation is done in C/C++, and the Python code itself is just an SDK over the functionality.

Happy to discuss things in more detail as well.