Files
Aurora.3/code/modules/lighting/lighting_profiler.dm
skull132 a3ec0cf45d Better SQL prepared statements (#2474)
The system used to be of complexity O(n^2). Essentially two for loops running per every argument. Which ended up being surprisingly slow (there were instances where I saw the argument parser as using quite a lot of CPU time).

This replaces it with a more linear algorithm. It's somewhere near O(n) where n is the length of the unparsed query. Which is more stable and faaaster. This comes with two changes, however:

Parameters inside the query now have to be delimited from both sides with : (colons). The alternative to this would be to use something like $n or just assume that space marks the end of a marker. Only the former is workable, the latter would break a few queries already.
Arguments in the argument array no longer have to be prefixed by : (colons). So, while in the query you would write :thing:, you'd initialize the array of args as: list("thing" = somevar). It could be made to work without it, but eh, I think this is fine.
Argument validation is slightly weaker. What I mean by this is that with the old system, unused keys would result in an error. This is no longer a thing. Missing keys will still result in an error, however.
One more improvement: double delimiting removes an edge case where if key A partially covers key B, depending on the order, key A would mangle key B.
Updated and tested all queries that I could find. So this should be good.
2017-05-29 21:17:41 +03:00

42 lines
999 B
Plaintext

// Writes lighting updates to the database.
// FOR DEBUGGING ONLY!
/proc/lprof_write(var/atom/movable/obj, var/type = "UNKNOWN")
if (!lighting_profiling || !obj || !establish_db_connection(dbcon))
return
var/x = null
var/y = null
var/z = null
var/name = null
var/locname = null
if (istype(obj))
name = obj.name
locname = obj.loc.name
x = obj.loc.x
y = obj.loc.y
z = obj.loc.z
var/static/DBQuery/lprof_q
if (!lprof_q)
lprof_q = dbcon.NewQuery({"INSERT INTO ss13dbg_lighting (time,tick_usage,type,name,loc_name,x,y,z)
VALUES (:time:,:tick_usage:,:type:,:name:,:loc_name:,:x:,:y:,:z:);"})
lprof_q.Execute(
list(
"time" = world.time,
"tick_usage" = world.tick_usage,
"type" = type,
"name" = name,
"loc_name" = locname,
"x" = x,
"y" = y,
"z" = z))
var/err = lprof_q.ErrorMsg()
if (err)
log_debug("lprof_write: SQL Error: [err]")
message_admins(span("danger", "SQL Error during lighting profiling; disabling!"))
lighting_profiling = FALSE