fnGetNotes(int) perforamance

fnGetNotes(int) perforamance

kkudikkudi Posts: 77Questions: 0Answers: 0
edited July 2010 in General
Hi Allan,

I have profiled my interaction with dataTables and my code on IE7 which is considerably lower than Firefox and Safari 5 and Chrome, and would like to ask if there's an alternative way to the following.

[code]

var index = table.fnAddData(row, false);

var tr = table.fnGetNodes(index);

[/code]

I have realized that if these two lines of code are contained within a loop, then the _fnNoteToDataIndex ( which is called from fnGetNodes) has a big execution time. Is there an alternative way so that when I add a row to the table to be able to retrieve that tr element almost without any additional delay?

Thanks

Replies

  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin
    edited July 2010
    fnAddData returns an array in indexes (which point to the aoData array - so I think the fastest way this can be done is:

    [code]
    var index = table.fnAddData(row, false);
    var tr = table.fnGetNodes(index[0]);
    [/code]
    That is basically the same as:

    [code]
    var index = table.fnAddData(row, false);
    var tr = table.fnSettings().aoData[index[0]];
    [/code]
    Also, unless I'm missing something - I don't actually see where fnGetNodes is calling _fnNodeToDataIndex(). That function is only called from fnDeleteRow, fnGetData, fnGetPosition and _fnNodeToDataIndex.

    Regards,
    Allan
  • kkudikkudi Posts: 77Questions: 0Answers: 0
    I think I might have confused myself. You're right. I failed to see that
    _fnNodeToDataIndex is not called from fnGetNodes actually. It was from fnUpdate.

    [code]
    var iRow = (typeof mRow == 'object') ?
    _fnNodeToDataIndex(oSettings, mRow) : mRow;

    [/code]

    there's no faster way for this is there?
  • kkudikkudi Posts: 77Questions: 0Answers: 0
    I have also ntoiced that even though fnAddData returns an array of indices ( even for adding one row would return an array of length 1)
    if i do , fnGetNodes(index) does not fail. Whereas the correct would be fnGetNodes(index[0]).
    This puzzles me. Any idea why?

    Thanks
    Andreas
  • allanallan Posts: 63,210Questions: 1Answers: 10,415 Site admin
    Hi Andreas,

    1. Speed of _fnNodeToDataIndex - I can't think of a faster way to do this off the top of my head. I suppose one optimisation would be to check if the node is in the visible range (which would make it return with 10, by default, iterations around the loop if it matches). This is probably a fair optimisation to make since the passed node is far more likely to be visible than not. I'll look at adding this in.

    2. fnGetNodes with array as an index - I've no idea why this doesn't fail! I guess the returned value might be null or undefined...

    Regards,
    Allan
  • kkudikkudi Posts: 77Questions: 0Answers: 0
    edited July 2010
    Hi Allan,

    Thanks for your quick replies.

    I have thought of caching index[0] returned by fnAddData as map with the key being the row's id. So whenever I have an update on that row, then I could simply get the index via :

    [code]

    var indices = table.fnAddData(row_array, false);

    var index = indices[0];

    map[row_id] = index;

    --------------

    var index = map[row_id]

    table.fnUpdate(row_array, index, null, false);

    [/code]
This discussion has been closed.