Opened 14 years ago
Closed 14 years ago
#2209 closed defect (invalid)
FilteringTable sorting is deadly inefficient
Reported by: | Jonathan Bond-Caron | Owned by: | Tom Trenka |
---|---|---|---|
Priority: | high | Milestone: | 0.9 |
Component: | Widgets | Version: | 0.4.1 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description
The createSorter method introduces a highly inefficient comparison function:
i.e. it returns:
return function(rowA, rowB){
var idx=0; while(idx < sortFunctions.length){
var ret = sortFunctions[idx++](rowA, rowB); if(ret != 0) return ret;
} if we got here then we must be equal. return 0;
}; function
I don't think the developper realized this function would get called intensively!
i.e. for 300 records, there are 3725 calls made by Array.sort It should at the bare minimum return:
return function(rowA, rowB){
if(dojo.html.hasAttribute(rowA,"emptyRow")){ return 1; } if(dojo.html.hasAttribute(rowB,"emptyRow")){ return -1; }
var a = self.store.getField(self.getDataByRow(rowA), field); var b = self.store.getField(self.getDataByRow(rowB), field); var ret = 0; if(a > b) ret = 1; if(a < b) ret = -1; return dir * ret;
}
Even then, it should really be comparing only the row values directly, not going through the data store every time!
Change History (2)
comment:1 Changed 14 years ago by
Milestone: | → 0.5 |
---|---|
Owner: | changed from bill to Tom Trenka |
Priority: | high → normal |
severity: | critical → normal |
comment:2 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Actually, I did realize that, and actually...there happens to be a reason that the sorting function goes through the underlying store and not the row data; what you see in the row is not necessarily what the table is sorting on. For instance, if the column in question is representing a Date object, you have two options: take the value from the row, cast it to a Date, and use that for sorting...or you can grab the value that is already cast as a Date in the underlying store, and use that instead.
Thanks for the point out, but I'm going to close this as invalid. Optimizations are not bugs.