[Reconstruction learning] 01 reconstruction and performance, reconstruction learning 01 Performance
Refactoring does not mean better performance, but Refactoring can make performance optimization easier !!!
About writing high-performance code
Prerequisites for writing high-performance code:First, you have to have a program that can be adjusted.
Just as if someone asks you how to get along with your girlfriend, you must first have a girlfriend.
Writing high-performance code:
1. Time pre-Algorithm
Allocate resources to each component, including time and execution track. Each component cannot exceed its budget.
It is usually used for real-time systems with extremely high requirements.
2. Continuous attention
This method requires that any programmer should ensure the high performance of the system when doing anything at any time.
This method is very common and attractive, but it usually does not play a major role. (Original words of refactoring)
Any modification to improve performance usually makes the program difficult to maintain and slows down development.
In addition, once the performance improvement is distributed to every corner of the program, every improvement is only from a narrow perspective on program behavior.
Most of the events of a program are usually spent on half-Code. If you optimize all the Code equally, 90% of the optimization is effort-free, because your optimized code is rarely executed.
You spend time to make the program run faster. If you don't have a clear understanding of the program and spend time, that time will be wasted.
3. hotspot Promotion Method (My name)
Using this method, you do not need to pay special attention to the performance when writing code until you enter the performance optimization stage-usually in the later stages of development.
In the performance optimization stage:
First, use a certain measurement tool to monitor the running of the program and find the code that consumes a lot of time and space, that is, "Hotspot.
Then we need to optimize these hotspots, so we can spend less time to achieve better optimization results.
Help of Refactoring for Performance Optimization
First, a well-constructed code gives you enough time to adjust the performance, because it allows you to add features more quickly, more time is spent on performance issues (accurate measurements ensure that you use the time at the right place ).
Second, in the face of well-structured programs, you have a finer granularity when performing performance analysis. Therefore, the measurement tool places you into a program section with a smaller scope, however, it is easier to adjust the performance. Because the code is clearer, you can better understand your choice and better understand which adjustment plays a key role.