3 ms·
Cython is pretty much Python without bytecode interpreter, translated to C instead, but retaining the object model. That's why it's so slow. And the reason why
by int_19h 3y ago
Cython is pretty much Python without bytecode interpreter, translated to C instead, but retaining the object model. That's why it's so slow.
And the reason why the object model is the way it is, is because it's an entrenched part of the Python ABI. Sure, if you break that, you can do things a lot faster - this isn't news, people have been doing this with projects like Jython and IronPython that can work a lot faster. But the existing ecosystem of packages is so centered on CPython that this approach has proven to be self-defeating - you end up with a Python implementation that very few people actually use.
So, no, it's not because people are "very confused" or "nobody bothered to do it". It's because compatibility matters.
- crabbone 3y agoWell, again, you are confused... and, most likely the CPython developers didn't bother. No. You don't need the Python object model when implementing Python dictionary. You have evidence right in front of you: std::map bindings are successfully used in its place. Why even keep arguing about this? In fact, you can implement your own dictionary, and if you expose all the same mapping protocol, it will work the same as the built-in one. Do you have to use Python objects for this? -- absolutely no. You can convert at the interface boundary. Experience shows that this works noticeably better than using Python objects all the way. Why did the original CPython developers not do it? -- I don't know, can only guess. I already wrote what my guess is. And, in all sincerity, CPython has a lot more and a lot worse problems. Compared to the rest of the codebase, the dictionary object is fine. So, if anyone would seriously consider improving CPython's performance they wouldn't touch dictionaries, at least not at first.
- int_19h 3y agoYou don't need a Python object model when implementing a highly specialized dictionary that can only store very specific data types. But Python dict is a generic collection type that is designed to store any Python object (or rather, reference to such, since Python has reference semantics for anything). And this part: > if anyone would seriously consider improving CPython's performance they wouldn't touch dictionaries, at least not at first. is just straight up nonsense, given how many times over Python's history dicts have been substantially rewritten. As it happens, I work on Python dev tooling, and the CPython team changing internal data structures for perf reasons has been a recurring headache for me, so I know full well what I'm talking about here.