Hacker News new | ask | show | jobs
by rat87 4455 days ago
The default python implementation(cpython) compiles to bytecode before interpreting(the default c implementation of ruby also does this as of 1.9, before that it did straight interpretation). The difference between compiling to bytecode ahead of time vs at run time is more of a packaging difference and probably not the biggest cause of the speed gap between the languages, although I suppose the python import mechanism doing strange stuff and hitting filesystem too often could slow things down. The reason the most common java implementation(oracle hotspot/openjdk) is fairly fast(there are other fast implementations) is that it includes a fast interpreter written in assembly(although a c++ backup version exists for non-x86 ports) and a good just in time compiler. It also has a much more advanced gc then python. Another thing that makes a difference is that python has a global interpreter lock that only allows one python thread(c extensions can run several of their own threads) to run at a time(despite the number of cpu cores/max native threads) because python's refcounting gc would cause significantly worse single threaded performance if multiple threads were to be run at the same time.
1 comments

Thanks for the explanation. I am fairly familiar with the Java internals, but I haven't used Python much, and was just using it as an example. I didn't realise that it was compiled to bytecode before interpreting. I suppose it doesn' make sense for any production-ready language to not have at list a JIT compilation system now that I acually think about it.