Nick,
I've finally got around to implementing my item database. It works just fine, except for one problem. It's slow. Very very slow. Not just in loading (it takes about 8 seconds to load, but since that's done at the start of a session it doesn't bother me), but in execution.
Let me give details of the exact setup, and then I'll show you just how slow it is.
The datafile I'm loading is 725kb, comprising 28,615 lines. Roughly in the same format as I mentioned earlier:
Affects: HITPOINTS by +1000
There's other things in there too, but I've got the code loading everything into a lua table just fine, using the object name as the key in the table.
Now, the trigger matches on *, and runs through a script that basically has to search the entire table of items (comprising some 2715 objects) and then replace the found text (if any) with the text+stats.
function mytrigger (name, line, wildcards, styles)
local temp;
for k, v in ipairs (styles) do
for k1, v1 in pairs (db) do
if v1["short_d"] ~= nil then
if string.find(v.text, nocase(v1["short_d"])) then
local temp_line = build_lore(v1)
v.text = string.gsub(v.text, nocase(v1["short_d"]), v1["short_d"]..' ' ..temp_line)
end -- if
end -- if
if v1["long_d"] ~= nil then
if string.find(v.text, nocase(v1["long_d"])) then
local temp_line = build_lore(v1) --["damage"]
v.text = string.gsub(v.text, nocase(v1["long_D"]), v1["long_D"]..' ' ..temp_line)
end -- if
end -- if
end -- for
ColourTell (RGBColourToName (v.textcolour), RGBColourToName (v.backcolour), v.text)
end -- for loop
Note ""
end -- function
Now, as you can see, on every line, it has to loop through 2700 objects, and use a string.find on the line for each of them. I knew it would be slow, but I never knew just how slow....
My test: I have a linux machine, and my windows machine, each connected to a gigbit switched network. To test the speed, I connect to the linux machine, and issue the following command: "time cat /etc/termcap-BSD". The file is 16470 lines long, and 706385 bytes. With no triggers enabled, this takes 0.525 seconds to send the entire file to mushclient. With the trigger enabled, it takes 3 minutes, 9 seconds. It's roughly 360 times slower with this trigger.
My machine is a dual-core athlon, each core is 1.7GHz, and I have 2gb of RAM. My video card is a 7800GT, with 256MB of memory and the latest drivers.
Your thoughts ? |