ID:138710
 
Execute LoadWorld_Fast() twice, and it will take almost six times longer the second time...

why?

Code:
proc
gettype(n)
switch(n)
if(1)
return /turf/red
if(2)
return /turf/blue
if(3)
return /turf/green
if(4)
return /turf/orange
if(5)
return /turf/pink
if(6)
return /turf/yellow
mob/verb
readtotext()
var/savefile/f = new("world_fast.sav")
var/ff = file("test.txt")
f.ExportText("/", ff)
fillrand()
for(var/x = 1, x < 256, x ++)
for(var/y = 1, y < 256, y++)
var/n = rand(1,6)
var/typet = gettype(n)
new typet(locate(x,y,1))
clearworld()
for(var/turf/t in world)
del(t)

SaveWorld_Fast()
var/savefile/f = new("world_fast.sav")
var/list/l = new
for(var/turf/t in world)
if(!istype(t,/turf/black))
l += "t=[t.type];x=[t.x];y=[t.y];z=[t.z]"
f << l

LoadWorld_Fast()
var/timestart = world.timeofday
if(!fexists("world_fast.sav")) return
var/savefile/f = new("world_fast.sav")
var/list/l = new
f >> l
for(var/t in l)
var/list/params = params2list(t)
var/path = text2path(params["t"])
var/xx = text2num(params["x"])
var/yy = text2num(params["y"])
var/zz = text2num(params["z"])
new path(locate(xx,yy,zz))
world << world.timeofday - timestart


Problem description:
I would expect this block of code to take approximately the same amount of execution time every time... especially considering the file size is not changing in between successive loads.
I could be wrong, but from the looks of your code, the only thing I could see to slow it down would be how the server handles file pointers, locks, etc. It's probably waiting for the first file pointer to be closed before opening the file a second time.
Don't quote me on this, as I'm not a BYOND developer, I can't tell you how this would be handled.

Try changing:

    LoadWorld_Fast()
var/timestart = world.timeofday
if(!fexists("world_fast.sav")) return
var/savefile/f = new("world_fast.sav")
var/list/l = new
f >> l
for(var/t in l)
var/list/params = params2list(t)
var/path = text2path(params["t"])
var/xx = text2num(params["x"])
var/yy = text2num(params["y"])
var/zz = text2num(params["z"])
new path(locate(xx,yy,zz))
world << world.timeofday - timestart


To:

    LoadWorld_Fast()
var/timestart = world.timeofday
if(!fexists("world_fast.sav")) return
var/savefile/f = new("world_fast.sav")
var/list/l = new
f >> l
for(var/t in l)
var/list/params = params2list(t)
var/path = text2path(params["t"])
var/xx = text2num(params["x"])
var/yy = text2num(params["y"])
var/zz = text2num(params["z"])
new path(locate(xx,yy,zz))
world << world.timeofday - timestart
f = null


If I'm right in my thinking, this should cause the file pointer to be closed in order for it to be used immediately in the next function call.
Try using this, and tell if it works. I've never tried it.
http://www.byond.com/docs/ref/info.html#/savefile/proc/ Unlock
Wait, why is is running twice? If it is loading the world, shouldn't it only have to run once?