Page 1 of 1

LUBE issue

Posted: Sun Nov 18, 2012 6:48 am
by Cowinatub
I've been using LUBE to program a network game for a couple weeks now, and recently I've noticed that the server I'm using gradually slows down over time. This is starting to get really annoying, and sometimes completely unplayable. Is there anything I can do about this, or is it just an issue with the library?

Re: LUBE issue

Posted: Sun Nov 18, 2012 8:47 am
by Robin
This looks suspect:

Code: Select all

function addline(text)
    LineNumber = LineNumber + 1
    Lines = Lines .. '\n' .. text
end
Try commenting out the last line in the function. You'll get no backlog, but hopefully it won't slow down any more either.

What I would do:
  • Replace Lines = '' by Lines = {}
  • Change addline to

    Code: Select all

    function addline(text)
        if #Lines > 100 then -- something like that
            table.remove(Lines, 1)
        else
            LineNumber = LineNumber + 1
        end
        Lines[#Lines+1] = text
    end
  • Change the drawing code to: (you might want to experiment with that)

    Code: Select all

    for i, line in ipairs(Lines) do
        love.graphics.print(line, 0, 780 + (i - LineNumber) * 14)
    end
EDIT: to be clear, the first part was a test to see if the slowing down was really due to addline. The second part is a proposed solution. Also, here's why:
Your string variable Lines kept on growing, and when you do "a = a .. b", Lua makes a new string object every time, and that gets more and more expensive when your string grows. My proposed solution uses a table, because it is easier to remove the lines you can no longer see and can thus be safely removed.

Re: LUBE issue

Posted: Sun Nov 18, 2012 9:13 am
by Cowinatub
Thanks for the help! I can sleep easy now knowing that the library I chose is efficient enough for my purposes.