Parsing Java because language is slow

Source: Internet
Author: User

Java in the early (example JDK1.2 once) this is very slow. Maybe it is because there are a lot of optimizations to improve the version number of the device, Java which is getting faster, so this is now very much Java and what is a slow controversy for C/s + +.

I want my own understanding. Talking about the effect of Java Factor program execution speed.

1. GC Recovery

As we all know, a very big step forward in Java vs. C + + is the GC mechanism. It can be very large programs to avoid the occurrence of common memory leaks in C + +. But it also comes at a price. That is because the JVM manages all of the memory allocation release, when the memory is not enough to be recycled, each recovery has to scan the entire heap, and then to move some memory data, the new generation OK. The hypothesis is the GC of the old age. Will cause the program to lag for some time. Very often it is unacceptable. Also greatly slows down the execution of the program. Although the GC algorithm is constantly improving. But also belongs to only can optimize cannot cure.

2. Explanatory language

Java for cross-platform. Instead of being compiled directly into a machine instruction, it is compiled into bytecode, which the JVM needs to load in order to execute the code.

In this process, it takes time to load the bytecode. Then it takes time to explain the execution.

Do the same thing. Compiled languages can be compiled directly into machine code. The CPU executes these instructions directly while Java is compiled into bytecode, and when executed the JVM translates the bytecode into the executable instructions of the target machine, where it adds a layer of indirection, which also reduces execution speed.

3, JIT consumption of resources

The JIT is the Java may version number of the improved function, can be the commonly executed method or block of statements immediately compiled into machine code, which can really speed up execution.

However, such a compilation is instantaneous, and the program itself to grab the execution of resources, it will slow down the speed of program execution.

4. Stack-based instruction set

The compiler language uses the instruction set based on the target platform register. This makes full use of the Register's speed.

Java for portability, there is no register that binds to a target platform. Instead, a stack-based instruction set is used. Frequent stack memory visits can result in slower speeds, and generally compiling the same statement produces more instructions than the register instruction set.

5. Bulk use of heap memory

Object creation in Java is managed by the JVM. You can avoid cross-border or null-pointer access problems that are common in C + +. So objects are mostly created on the heap, not on the stack, and are typically more expensive to create and maintain.

6. AOT Technology

AOT technology is capable of installing bytecode into the target platform. Compile the running files of the target platform so that the target platform can run the running files directly. Speed can be achieved by the level of the compiler class language. However, this can result in the loss of the dynamic loading functionality that Java has, and all bytecode is compiled into the running file, regardless of whether it is used at run time, and resulting in a larger volume of executable files produced than bytecode.

In general, Java has features such as cross-platform and memory management. Has brought a lot of progress to the development efficiency. But there are pros and cons to everything. This is accompanied by a reduction in the efficiency of execution. Fully understand these strengths and weaknesses, talent at the right time to choose the right technology, in order to maximize performance.

Finish

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Parsing Java because language is slow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.