Technical summary of project development && Exploration of JS execution efficiency

Preliminary development is complete, we need to test it later

One thing that made me very concerned about the process is the execution efficiency of JS. After changing a
certain place
, it is 100 times faster than that to explore the specific reasons.Insert picture description hereInsert picture description here

Using the JSON+array structure to store the rows and columns (time and number) of the data results in the different number of arrays, which consumes a lot of time:

Way 1

Test the following code()

console.time('time'); 
	var json={
    
    };
	for(var j=0;j<DEFECT_CNAME.length;j++){
    
    //把缺陷名按顺序放入JSON中  为对应DEFECT_CNAME以便循环输出
		json[DEFECT_CNAME[j]]=new Array();//放入数组
		for (var i = 0; i < PRODUCE_TIME.length; i++) {
    
    
			json[DEFECT_CNAME[j]][i] = new Array();
			for (var x= 0; x < 3; x++) {
    
    
				if(x==0){
    
    
					json[DEFECT_CNAME[j]][i][x] = PRODUCE_TIME[i];
				}else{
    
    
					json[DEFECT_CNAME[j]][i][x] = 0;
				}
			}
		}
	}	

	console.timeEnd('time'); 	
	var j=0;

The execution results are as follows:
Insert picture description here

time consumingInsert picture description here

Way 2
console.time('time'); 
	var json={
    
    };
	for(var j=0;j<DEFECT_CNAME.length;j++){
    
    //把缺陷名按顺序放入JSON中  为对应DEFECT_CNAME以便循环输出
		json[DEFECT_CNAME[j]]=new Array();//放入数组
		for (var i = 0; i < 2; i++) {
    
    
			json[DEFECT_CNAME[j]][i] = new Array();
			for (var x= 0; x < PRODUCE_TIME.length; x++) {
    
    
				json[DEFECT_CNAME[j]][i][x] = 0;
			}
		}
	}
	console.timeEnd('time'); 

The results of the implementation are as follows:
Insert picture description here
time-consuming Insert picture description here
is indeed about three times faster, but obviously the problem is not here

And three days after all the development tasks are actually completed, the speed is as shown in the figure:Insert picture description here

Recalling the development process, there is a high probability of benefiting from:
1. The table is finally indexed on the data side.
2. My query in the background is limited based on the number of pages and the number of displays. The amount of data that needs to be processed at the front and back ends is small. At the beginning, I check 50,000 items in turn...
3. The query statement is optimized, the SQL is modified, and the double GROUP BY is used. Preliminary data processing is placed on the query, which simplifies the logic of data processing in the front and back end.

Technical summary:

The priority of data processing is:

1、

Database optimization is the absolute priority, and methods such as sub-database sub-table/add index are the most efficient and the best optimization effect;

2、

Then there are SQL statements to look up tables for processing according to different needs, which is more efficient than processing in the background and foreground;

3、

What SQL can't handle, the logic that needs to be based on the needs of the user's operation, is the real need to use the front and back JAVA/JS to code the code.
But there are a lot of considerations in this part, such as the object gc problem of JVM to control the number of objects in the program, logic optimization uses less recursion, less if and more use switch, syntactic sugar, polyclonal interface, and even multithreading in certain situations...java There is still a lot of room for improvement in programming ability

4、

The front-end JS does not need to write complex logic, and the performance of the client accessed by different customer services is different, which may cause a different sense of user experience

5、

This development has learned a lot of things, and more importantly, learned a lot of ways to solve problems. I feel that I have grown. The
most important thing is that I am really in development for the first time, and I feel what it brings in my work. Happiness, it’s really great working in it.
I hope this momentum will continue in the future.

Guess you like

Origin blog.csdn.net/Beatingworldline/article/details/113647751