Skip to content

Commit 47a6c46

Browse files
committed
Avoid copying data on compare page unless it is really necessary
1 parent 4acb78f commit 47a6c46

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

‎site/static/compare.html‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,16 @@ <h3>Brief explanation</h3>
115115
{
116116
letfilter=document.querySelector("#filter").value;
117117
lettest_names=unique([...Object.keys(data.a.data), ...Object.keys(data.b.data)]);
118+
letisCopied=false
118119
for(letnameoftest_names){
119120
if(!name.includes(filter)){
121+
if(!isCopied){
122+
// Copying data is very expensive
123+
// This branch ensures that we avoid copying
124+
// if there are no filters (which is the most common case)
125+
data=JSON.parse(JSON.stringify(DATA));// deep copy
126+
isCopied=true
127+
}
120128
deletedata.a.data[name];
121129
deletedata.b.data[name];
122130
}
@@ -331,7 +339,6 @@ <h3>Brief explanation</h3>
331339
},state);
332340
make_request("/get",values).then(function(data){
333341
DATA=data;
334-
data=JSON.parse(JSON.stringify(DATA));// deep copy
335342
populate_data(data);
336343
});
337344
}
@@ -350,8 +357,7 @@ <h3>Brief explanation</h3>
350357
load_state(make_data);
351358

352359
functionrerender(){
353-
letdata=JSON.parse(JSON.stringify(DATA));// deep copy
354-
populate_data(data);
360+
populate_data(DATA);
355361
}
356362

357363
document.querySelector("#filter").addEventListener("change",rerender);

0 commit comments

Comments
(0)