Why does Java have much better performance compared to other interpreted languages like Python? I know this probably has something to do with the fact that it's compiled beforehand, but what about concurrency?

How is the JVM able to perform so much better with concurrent programs, whereas interpreted languages have to do deal with things like global interpreter locking etc, that really slow things down?

解决方案

This is a really interesting question, but I'm not sure there's a simple way to answer it. JVMs these days use a range of highly aggressive optimizations to try to improve performance. Here are a few:

Dynamic compilation: Most good JVMs can dynamically compile the bytecode directly into machine code, which then executes at native speeds.

Polymorphic inline caching: Many JVMs use inline caching to try to improve the performance of method dispatching by remembering which functions have been called in the past.

Static typing: Since Java is statically-typed, bytecode instructions rarely have to do expensive introspection on the type of an object to determine how to perform an operation on it. Field offsets can be computed statically, and method indices in a virtual function table can be precomputed as well. Contrast this with languages like JavaScript, which don't have static typing and are much harder to interpret.

Garbage collection: The JVM garbage collector is optimized to allocate and deallocate objects efficiently. It uses a combination of mark-and-sweep and stop-and-copy techniques to make most allocations really fast and to make it easy to reclaim lots of memory quickly.

Known choke points: Rather than having a huge VM lock, some JVM implementations automatically insert extra code into each piece of compiled/interpreted code to periodically check in with the VM and determine whether they can keep running. That way, if the JVM needs to do garbage collection in only a few threads, it can do so while the other threads are running. If it needs to do a stop-the-world operation, it will only occur when the threads hit specific points, meaning that simple operations don't have to continuously check in with the VM state.

There are many, many more optimizations in place that I'm probably not aware of, but I hope that this helps you get toward an answer!

比Java语言更好,为什么Java比其他解释语言具有更好的性能?相关推荐

  1. Python到底是什么样的语言? Python和Java比谁更快? TensorFlow的主体是用Python写的吗?

    Python到底是什么样的语言? Python和Java比谁更快? TensorFlow的主体是用Python写的吗? Python到底是什么样的语言? 解析: 这里是一些关键点:Python是解释型 ...

  2. c语言 python java_C语言、C++、Java,Python之间的区别,哪个更有前景,哪个更难 ?...

    从这四种语言的难度.受欢迎度还有作用以及优点缺点给楼主做一个全面的分析,我们可以从中了解其区别,以及难易程度.至于今后可以用到的或者是前景问题,根据自己的职业发展大家可以自己做个分析.最后会总结一下他 ...

  3. java和python的优势_Java和Python哪个更好?解读Python对比其他语言的优势

    人生苦短,我用 Python,为啥这么说,因为我们码农圈有金句:学完Python,便可上天 ~ 首先 我要向各位坦诚,我对 Python 的喜爱也是从几年以前才开始的.不经历长期的痛苦教训,我们是不会 ...

  4. Java语言基础大合集!让兴趣助你更好的学习,赢得未来江湖

    前言 众所周知,Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承.指针等概念,因此Java语言具有功能强大和简单易用两个特征. Java语言作为静态面向 ...

  5. java基础学习总结一(java语言发展历史、jdk的下载安装以及配置环境变量)

    最近一段时间计划复习一下java基础知识,使用的视频课程是尚学堂高淇老师的,上课过程中的心得体会 直接总结一下,方便以后复习. 一:计算机语言的发展 1:机器语言,最原始的语言,主要有"01 ...

  6. 零基础是学java还是python-零基础更适合学习Java还是python?

    原标题:零基础更适合学习Java还是python? 最近有小伙伴向云和数据小编咨询,说想学习一门编程语言,但是没有任何基础,问是学习Java好还是学python更合适?对于这位小伙伴的问题,小编觉得有 ...

  7. C++, C#, Java, VB.NET,到底该选择哪一门语言?

    Posted in 程序人生 at 11:08 pm by 李建忠 接到一位读者朋友的来信,告诉我他在各个编程语言之间徘徊了很长时间,最后在Google Trends的启发下终于选择了Java. 事情 ...

  8. 【详解】Java语言的特点以及Java语言与C/C++的比较

    文章目录 一.Java语言的特点 1.跨平台性/可移植性 2.面向对象 3.简单性 4.分布性 5.健壮性 6.安全性 7.解释型 8.多线程 二.Java与C/C++的区别 1.指针 2.多重继承 ...

  9. java高频面试_C ++或Java,高频交易哪个更快?

    java高频面试 总览 关于什么是高频交易的最佳解决方案,存在不同意见. 问题的一部分是高频交易的变化超出您的预期,另一部分是更快的含义. 我的看法 如果您有一个典型的Java程序员和一个典型的C + ...

  10. Go语言出现后,Java还是最佳选择吗?

    阿里妹导读:随着大量新生的异步框架和支持协程的语言(如Go)的出现,在很多场景下操作系统的线程调度成为了性能的瓶颈,Java也因此被质疑是否不再适应最新的云场景了.4年前,阿里JVM团队开始自研Wis ...

最新文章

  1. .net framework 4.0安装_Win 7无法安装Microsoft .NET Framework 4.6.2
  2. python 编码规范 PEP8整理
  3. Qt的Oracle数据库QOCI驱动问题
  4. WinSock网络编程实用宝典(一)
  5. vector的reserve和resize
  6. teamcity_TeamCity构建依赖项
  7. oracle消耗内存的查询,在AIX中计算ORACLE消耗的私有内存总数
  8. 浅议一种低成本的48V蓄电池组电压电流采集模块
  9. 被问到最多的淘口令API调用方法
  10. Typora安装主题方法
  11. 双目摄像机获取标定图片
  12. mysql中临时字段_MySQL临时表
  13. python from. import失败_彻底搞懂Python 中的 import 与 from import
  14. Linux操作系统与Shell编程
  15. 为什么每个语言都要和Java作比较?一文带你搞懂!
  16. 【C语言训练】自由落体问题
  17. jQuery发送ajax请求
  18. 互联网技术研发管理之绩效管理提升
  19. 企业成功的秘密:成为独角兽
  20. 风格迁移-风格损失函数(Gram矩阵)理解

热门文章

  1. 122_Power PivotPower BI不连续日期的日环比
  2. java lambda表达式详解_Java8新特性:Lambda表达式详解
  3. ubuntu18找不到wifi适配器
  4. python分析BOSS直聘的某个招聘岗位数据
  5. 蓝奏云数值验证码识别,python调用虹鱼图灵识别插件,超高正确率
  6. 重庆火锅哪家强,Python 帮你探探店
  7. Error解决:hive中的数组越界异常IndexOutOfBoundsException
  8. 漫步微积分三十五——弧长
  9. 【渗透测试】XSS注入原理
  10. 数字图像处理--灰度图转伪彩色图