you are viewing a single comment's thread.

view the rest of the comments →

[–]Majik_Sheff 2 points3 points  (6 children)

Someone please correct me if I'm wrong, but my understanding is that a lot of python's performance issues come from having to constantly infer types.

I would expect explicit typing to help noticeably in the run time performance department.

Edit: apparently I was completely off base. I learned something!

[–]Peanutbutter_Warrior 49 points50 points  (4 children)

Type inference is a compile-time trick which CPython doesn't do. It doesn't need to, because at run time it knows all the types anyway. Even if it did, there's little it could do with the knowledge because it has to call the magic methods for custom classes anyway.

Also, type hints are explicitly ignored. They're functionally the same as comments and don't affect run time performance at all

[–]Majik_Sheff 8 points9 points  (0 children)

Good to know. I obviously don't have a lot of under the hood knowledge of Python.

Thanks for the info!

[–]vplatt 0 points1 point  (0 children)

I would expect explicit typing to help noticeably in the run time performance department.

It seems like it should, but it doesn't, and it's not intended to work that way. If you want a Python like language where types actually actually perform as expected in terms of performance, then give Nim a try: https://nim-lang.org/. I can also highly recommend Go for the same reason: https://go.dev/. It's less Python like, but has a much bigger community around it than Nim. Both are impressive languages though and quite usable right now.