Slow when too many lines

Slow when too many lines

DrakoDrako Posts: 73Questions: 0Answers: 0
edited May 2011 in General
Hi,

i want to know if there is anything i can do on my code to speed up the table, when i get over 150 lines (9-10 columns) it gets very slow, usually taking between 6 to 10 seconds, and most of the time (on chrome) a window will popup saying the javascript is taking too long and if i wish to cancel it or wait.

my code is not server side because im using sqlite and i didnt found a way to do it.. (is there any?)


im building the table like this

[code]
foreach ($db->query("SELECT * FROM PROBLEMA WHERE LOTE_EXTERNO_ID_ASSOCIADO='$l_ext') as $row)
{
$tablecontents .= "

{$row['LOTE_EXTERNO_ID_ASSOCIADO']}
{$row['Numero_Placa']}
{$row['Defeito']}
{$row['Posicao']}
{$row['Reparo']}
{$row['Nota_Fiscal']}
{$row['Data']}
{$row['Responsavel']}
{$row['PROBLEMA_ID']}
" ;
}
echo $tablecontents;
}[/code]


thanks!!!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm very surprised that Chrome is taking several seconds for only 150 rows. Very surprised. Can you give us a link please?

    Allan
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    Hi allan.. thanks for the help..

    here is a link to a 207 row table, it is taking a very long time to build it (just took me 20 seconds)

    http://www.wi.com.br/wi04/defeitos.php?l_ext=117006661&nota=10179
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    getting it up so it will be visible again =)

    if i cant fix this i will have to change all code to mysql, hope there is a solution to my problem..

    thanks!
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If you comment out the DataTables initialisation ( oTable = $('#table1').dataTable( { ) - does it "fix" the problem? There is something very odd going on there - I think there might be an infinite loop somewhere which is killing the browser. My Safari instance shows that some items on the page have been loading for over an hour....

    Allan
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    edited May 2011
    yes, if i dont initialize datatables it loads fast (1-3 seconds).

    where do you think this infinite loop might be?

    thanks for the help!

    edit: link without datatables

    http://www.wi.com.br/wi04/defeitos2.php?l_ext=117006661&nota=10179
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Thanks for the link - according to the Chrome profiler there is a selector somewhere which is taking a very very long time to complete. It looks like it is in the document ready function - but I can't immediately see which one. I think the next step is to remove all code apart from your DataTables initialisation and then add it back in function by function and see where the slow down occurs.

    Allan
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    seems like the jeditable is the problem

    this link has everything but the jeditable code

    http://www.wi.com.br/wi04/defeitos2.php?l_ext=117006661&nota=10179

    is there something wrong with my code?
    thanks for the help allan


    [code]


    var user = "<?php echo $_COOKIE["nome_usuario"];?>";
    if(user=='Cida' || user=='Kelly' || user=='Laura' || user=='Mary' || user=='Angela' || user=='Nayara' || user=='Diogo')
    {
    $('td:eq(1), td:eq(2), td:eq(3), td:eq(4), td:eq(5), td:eq(6), td:eq(7), td:eq(8)', oTable.fnGetNodes()).editable( 'update.php', {
    "callback": function( sValue, y ) {
    var aPos = oTable.fnGetPosition( this );
    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
    $('.dataTables_scrollBody').scrollTo($(this));
    },
    "submitdata": function ( value, settings ) {
    var aPos2 = oTable.fnGetPosition( this );
    var aoColumns2 = oTable.fnSettings().aoColumns;
    var hValue2 = aoColumns2[aPos2[1]].sTitle;
    var id2 = oTable.fnGetData( aPos2[0] );

    return {
    "row_id": this.parentNode.getAttribute('id'),
    "column": oTable.fnGetPosition( this )[2],
    "value2": hValue2,
    "id2": id2[9],
    "id": 'PROBLEMA_ID' ,
    "tab": 'PROBLEMA'
    };
    },
    "height": "20px",
    "event" : "dblclick",
    "tooltip" : "Clique 2 vezes para editar..."

    } );
    }[/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I suspect that this selector is being _very_ slow:

    [code]
    $('td:eq(1), td:eq(2), td:eq(3), td:eq(4), td:eq(5), td:eq(6), td:eq(7), td:eq(8)', oTable.fnGetNodes())
    [/code]
    If you replace it with:

    [code]
    $('td', oTable.fnGetNodes())
    [/code]
    Is it faster? Obviously not what you want - but a good test. Perhaps

    [code]
    $('td:lt(9)', oTable.fnGetNodes())
    [/code]
    would be faster, while doing what is needed?

    Allan
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    edited May 2011
    $('td', oTable.fnGetNodes())

    and

    $('td:lt(9)', oTable.fnGetNodes())

    are way faster..

    but how do i use the selector if i want to edit columns 3, 6 and 8 for example?

    thanks a lot for the help Allan!
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    i found the jquery slice selector, but cant figure out how to use it =(
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think that this one is a question for the jQuery message boards now as it's moving beyond me knowledge of jQuery selectors and the optimisations in sizzile. I'd ask how that selector can be optimised on the jQuery message boards or Stack Overflow :-)

    Allan
  • DrakoDrako Posts: 73Questions: 0Answers: 0
    Im asking there, thanks a lot =)

    i hope i can find an answer to get individual columns, i just noticed that my code to walk between rows with the cursor gets slow on big tables too, probably for the same reason (using eq selector).
This discussion has been closed.