News for hackers. Stuff that matters.
Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by nemothekid on Tuesday February 09, 2021 @01:36PM (#26081001)
Armin Ronacher, author Flask, actually has a good talk about this. The gist of it the way Python's internals leak into the language makes it very difficult to build a performant JIT that wouldn't break a large amount of userspace code.

Python lets you do _far_ more shenanigans that Javascript does; and a lot of large libraries depend on some of that behavior. Breaking it would probably cause a new 2 -> 3 situation.

https://www.youtube.com/watch?v=qCGofLIzX6g&feature=emb_titl...

Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by ak217 on Tuesday February 09, 2021 @02:20PM (#26081453)
> a lot of large libraries depend on some of that behavior.

Armin makes great points about path dependence of API design and how the CPython API leaks into the Python language spec. But the features being discussed are actually obscure (example: slots) or intended for debugging (example: frame introspection), and most libraries don't have a good reason to use them. We're stuck in a loop: people talk about how Python is special and can't use a JIT because its internals are not JIT-friendly, so we don't have a JIT, so implementers continue to make choices that are not JIT-friendly - not because they want to, but because they have no guidance.

The JIT doesn't have to be amazing on day 1. What it does have to do is show a commitment and a path to performant code, and illuminate situations where optimizations turn off. There's nothing fundamental in Python's design that prevents a JIT from working; a small number of rarely used dynamic features (that most people don't know about and don't know that they can negatively affect performance) should not be used to hold up interpreter design.

Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by thu2111 on Wednesday February 10, 2021 @07:48AM (#26088402)
GraalPython is on its way to solving this, by co-JIT-compiling both Python and the code of the native extensions simultaneously. However Python is a large language and ecosystem, so it'll take a while for the implementation to mature.
Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by Sohcahtoa82 on Tuesday February 09, 2021 @05:39PM (#26083410)
> Python lets you do _far_ more shenanigans that Javascript does

Does JavaScript let you do this monstrosity of terrible code?

    Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Dog(object):
    ...     def speak(self):
    ...             print("bark!")
    ... 
    >>> class Cat(object):
    ...     def speak(self):
    ...             print("meow!")
    ...
    >>> animal = Dog()
    >>> animal.speak()
    bark!
    >>> animal.__class__ = Cat
    >>> animal.speak()
    meow!
    >>>
Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by Zarel on Wednesday February 10, 2021 @05:07AM (#26087387)
A lot of people have responded "yes", but no one's taught you how yet, so here's some example code that you can paste into your browser's Devtools or Node's REPL:

    class Dog {
      speak() {
        console.log("bark!");
      }
    }
    class Cat {
      speak() {
        console.log("meow!");
      }
    }
    animal = new Dog();
    animal.speak();
    Object.setPrototypeOf(animal, Cat.prototype);
    animal.speak();
This will produce:

    bark!
    meow!
Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by tracker1 on Tuesday February 09, 2021 @05:49PM (#26083542)
Yes, you absolutely can. In fact, this was part of my ES5 Date constructor polyfill.
Re:Node.js 14 is over 20x faster than Python3.8 for fib(n) by detaro on Tuesday February 09, 2021 @05:43PM (#26083471)
You can replace an object's prototype in JS, wouldn't that do the same?