Java advanced Optimization Technology

Source: Internet
Author: User

 

Common:

1. optimized the cycle. Re-organize repeated subexpressions to improve the running performance of the loop body.

2. Reduce the number of objects used to improve the running performance.

3. reduce network transmission data to shorten the wait time.

 

Others:

1. The object pool technology is used to improve the utilization efficiency of objects.

The loss of performance is mainly caused by the creation and release of objects. Therefore, the creation and release of objects must be avoided. The object pool technology is used to pre-define an object pool and create a group of objects to be used first:

Enemy [5] Enemy = new enemy [5];

For (INT I = 0; I <5; I ++ ){

Enemy [I] = new enemy ();

}

Add a flag such as used and reset to identify the enemy status. To create an object, obtain an unused object from the object pool and initialize it using the reset method. to release an object, you only need to modify the flag for the next use. Java object pool technology: http://www.cnblogs.com/devinzhang/archive/2012/01/05/2313406.html

 

2. Try to replace the object with the basic data type

For example, a two-dimensional array is used to replace a simple object.

 

3. OptimizationAlgorithm

For example, scenarios and algorithms that do not require fine-grained writing are simulated using simple algorithms.

 

4. Other Optimizations

A. When extracting a string, try to return the substring instead of creating a copy.

B. Try to create as few temporary objects as possible.

C. If you can use a library function, do not create it yourself (the library function is optimized)

D. Map map = new hashmap ();

Hashmap map = new hashmap (); // higher performance, refactoringCode

E. When using the enhanced for loop and iterable, you need to create an object with caution.

F. Avoid the enum type.

G. Pay attention to floating point usage during embedded development. (Whether the processor supports floating point)

H. Compression of image resources, adding multiple image sets to one image (much smaller than individual and smaller, saving data blocks such as each header file and ending file, and combining the color palette)

 

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.