Skip to content

Commit 6ba7afe

Browse files
authored
Fix Chrome performance regression (#2960)
* Fix Chrome performance regression Now that dxSTable.rows is a getter, and not a variable, we need to be mindful about using it in for loops. On an ruTorrent with 20K torrents, putting it into the for loop, instead of copying it into a variable will result in 20K executions of the getter function and tank performance. By checking the rowcount once, before we start the loop, we can keep the getter (reducing the risk of OOS bugs), without suffering the performance penalty. Related to #2830 * Remove tr index attribute It looks like it has lost it's original purpose and is now identical on every single torrent when you first load it. It does look like it will increment as new torrents are adedd. But I don't see a lot of utliity. Nobody needs to reference the 57th torrent added to the client. It's also incurring a hefty performance penalty in the code. Removing it now makes syncDom 5x faster. From 270 ms on my machine to 57 ms reliabily in Chrome.
1 parent 1fb1b49 commit 6ba7afe

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

js/stable.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,14 @@ dxSTable.prototype.init = function() {
554554

555555
dxSTable.prototype.setBodyState = function(v) {
556556
this.tBody.css("visibility", v);
557-
for(var i = 0; i < this.cols; i++)
557+
const colcount = this.cols;
558+
for(var i = 0; i < colcount; i++)
558559
{
559560
if((this.colsdata[i].type==TYPE_PROGRESS) && this.colsdata[i].enabled)
560561
{
561-
for(var j = 0; j < this.rows; j++)
562-
{
562+
const rowcount = this.rows;
563+
for(var j = 0; j < rowcount; j++)
564+
{
563565
var id = this.rowIDs[j];
564566
if($$(id))
565567
{
@@ -726,7 +728,9 @@ dxSTable.prototype.scrollPos = function()
726728
mid = this.viewRows - 1;
727729
var vr =- 1;
728730
var str = "";
729-
for(var i = 0; i < this.rows; i++)
731+
732+
const rowcount = this.rows;
733+
for(var i = 0; i < rowcount; i++)
730734
{
731735
var id = this.rowIDs[i];
732736
var r = this.rowdata[id];
@@ -941,7 +945,7 @@ dxSTable.prototype.createIcon = function(icon) {
941945
}
942946

943947
dxSTable.prototype.createRow = function(cols, sId, icon, attr) {
944-
const attrs = { id: sId, index: this.rows, title: cols[0] };
948+
const attrs = { id: sId, title: cols[0] };
945949
if (sId == null) {
946950
delete attrs['id'];
947951
}
@@ -972,9 +976,10 @@ dxSTable.prototype.createRow = function(cols, sId, icon, attr) {
972976
}
973977
row.find("td:first-child div").prepend(this.createIcon(icon));
974978
const ret = row[0];
975-
const _e = this.tBodyCols;
976-
for (let i = 0; i < _e.length; i++) {
977-
ret.cells[i].style.textAlign = this.tHeadCols[i].style.textAlign;
979+
const _tBodyCols = this.tBodyCols;
980+
const _tHeadCols = this.tHeadCols;
981+
for (let i = 0; i < _tBodyCols.length; i++) {
982+
ret.cells[i].style.textAlign = _tHeadCols[i].style.textAlign;
978983
}
979984
return ret;
980985
}

0 commit comments

Comments
 (0)