The slowdown is when you use :
local str="hello".." ".."world".."!"
To replace this with a faster solution you need just a table where you put all the strings. And at the end you use table.concat to join them. This was 10x faster on my laptop when i measured it.
Code: Select all
-- a fast way of manipulating strings into a big string instead of using the slow way like this str=str.."some text "..value.."\n"
-- the speed improvement is almost 10x faster than the normaly used string appending version (also less memory used)
local String={}
function String.buffer()
return {}
end
function String.append(o,str)
table.insert(o,str)
end
function String.newline(o)
table.insert(o,"\n")
end
function String.indent(o,spaces)
local str=string.rep(" ",spaces)
table.insert(o,str)
end
function String.format(o,fmt,...)
local str=string.format(fmt,...)
table.insert(o,str)
end
function String.tostring(o)
return table.concat(o)
end
return String
- if you need to append strings for some reason do not do this in love.draw call, but in love.update call
- if you draw lot of text then use bitmap font instead of true type font