Current project, this year should be the first5ItemsReleaseNow, Passed through this5The ups and downs of the year make it easier for developers in the middle. The current team and5Years ago, the team was already two teams with no "intersection" at all, This will inevitably cause us to have a lot of incomprehension of the project, not understanding its original intention, not understanding its original design, not understanding itsCode... Do not dare to do anything you don't understand. You can only repair and supplement the required functions to complete the functions. From the development perspective, the overall design is missing, The code structure is messy. from a functional perspective, it is prone to errors and the running speed is extremely slow.
A project requires in-depth code reconstruction and performance improvement, and at least oneReleaseFor code refactoring, From a commercial point of view, it is very undesirable. First, it is highly risky. with drastic restructuring, how to ensure the original functions of the software is a big problem; And a wholeReleaseWhen a user obtains a new version, he does not see any new features or improvements. do you tell him that our code structure is veryElegent...; However, the performance improvement has to be done now, because it can greatly improve the performance, presumably the user can also accept a new version without new features.
So, We decided to useReleaseTime for performance optimization.
Of course, we do not plan to consider it from an academic perspective, This isO (N)OfAlgorithmThat isO (nlgn)...; We do not want to look at it from the perspective of language, Passing a reference is faster than passing a value. Class Members are initialized in the initialization list ...; Of course, It doesn't mean these are unimportant, However, these are common things that everyone should be aware, That is to say, we assume that this problem does not exist in our project; In addition, it is optimized from the language perspective, It will not help us to improve our performance much. From a macro, specific to our projectWorkflowOptimization. It mainly includes the following aspects:
I. centralized processing(Batch processing)
Centralize related operations, SlaveProgramIn principle, Perform the same operations in a centralized manner, Due to the principle of Data Locality, A lot of data can be directly transmitted fromCache, The speed is faster. However, we mainly consider another factor to reduce unnecessary repeated initialization. Assume that I have ten objectsUpdate, Generally, To DoUpdate, We must prepare some prerequisite data, If ten objects are processed separately, I want to initialize it ten times, However, if I first collect these ten objects and process them together, The prerequisite data is initialized only once. ForUpdateObjects are very useful. Of course, In this way, we can effectively reduce the number of function calls, It also helps improve performance.
Ii. reduce repeated operations (initialization)(Reduce repeated operations)
Repeated operation, When there is a loop, I should tryCommon, For example, the initialization of some input data is done outside the loop, which is also mentioned above. Second, for some global attributes and operations, We should put it in the memory and provide a global access point to get it directly, Instead of re-initializing it whenever necessary. For example, EachApplicationThey should all have their ownConfiguration, setting,If every time I need this information, Read from the file or the registry once, That's a waste of time, Especially when it comesI/OOperation. Of course, This is a bit likeCacheConcept, But it is far from enough.
3. Remove Redundancy(Avoid redundant operations)
Maybe you don't believe it, A project has been developed by many different people, Due to the misunderstanding and time constraintsWorkflowThe operation may be repeated, Careful inspection, Consider the entire process globally and you will find that, In fact, we have done a lot of things we should not do.
IV,CacheMechanism(Cache Mechanism)
CacheThe principle is to use space for time, Of course, this space refers to memory. We put some important intermediate information in the memory to greatly improve the search and update speed. The Common Data Structure isMap,For example, an object has the Length attribute, However, every time you get this length, you need to go through complicated time-consuming calculations, If some operations require a lot of use of this object and its attributes, We can create suchMap: Map <Object Pointer, Length>, In this way, I only needMapTo query, If an object is updated, We need to update thisMap,That is to say, maintenanceCache.
5. Delayed update(Defer update)
This is a strategy-based approach, For example 9.1 Before Demo To customers, We need to write the code and maintain the documentation, However, the time is very urgent, If we 9.1 I'm afraid I have to work hard before the day, But we know that customers only need to see the results of our software operation, He does not care about the document at the moment, Well, We 9.1 Write code before, The document is in Demo And then write it. Of course, this example does not encourage everyone to write the code first and then supplement the document, To illustrate some things, If resources are insufficient, We can look at it separately, We can skip this step, Not busy, When necessary, To ease the current tension. For example, from the code perspective, Suppose we have ten splines that need to be updated, Updating the equations that may include splines, graphic display, And its length, etc, If I have done all these things, The user may have to wait a long time, But we know that, The user performed this operation, He only needs to see updates on the image, As for the length, When he needs it, Or when we are idle, we can update it again, This makes the entire operation smoother.
This is what I useReleaseI believe there are a variety of Optimization Methods for software optimization. I hope this articleArticleI hope you can share some of your experiences.
(Moved from the previous blog)