ID:2686435
 
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
Would it be possible to have the compiler do an optimization step to flatten static strings embedded in other strings? For example,
"this is ["sparta"]"
takes nearly twice as long at runtime than
"this is sparta"


Example benchmark code (which also shows why this would be helpful, the SPAN macro)
/world
loop_checks = 0

#define BENCHTM(NAME, ITERS, CODE) \
do{ \
var/s = world.tick_usage ;\
for(var/j = 1 to 1000000) {\
for(var/i = 1 to (ITERS)) {\
CODE ;\
} ;\
} ;\
var/e = world.tick_usage ;\
world.log << "[NAME]: [(e-s) * world.tick_lag] ms" ;\
} while(0)


#define SPAN_WARNING(X) "<span class='warning'>[X]</span>"

/proc/build_text_native()
. = "<span class='warning'>meow</span>"

/proc/build_text_compiler()
. = SPAN_WARNING("meow")

/proc/build_why_no_optimize()
. = "<span class='warning'>["meow"]</span>"

/proc/main()
BENCHTM("native", 10, world << build_text_native())
BENCHTM("compiler", 10, world << build_text_compiler())
BENCHTM("the fuck", 10, world << build_why_no_optimize())


Benchmark results:
I've actually been giving this some thought, but I think in a case of string concatenation there's a way you can have what you want more readily. Specifically, if you use ("before" + middle + "after") instead of "before[middle]after", the compiler can easily handle this with constant strings.

But, I suspect the reason you want this is so you can use the same macro with non-constant stuff, so I totally get that.

I've actually been looking into the problem and I suspect this might be something I could work into the beta series for 515.