On Thursday, 6 February 2014 at 11:44:34 UTC, Michel Fortin wrote:
That thread about buildPath started like this: "Walter and I were talking about eliminating the surreptitious allocations in buildPath". But reference counting will do nothing to eliminate surreptitious allocations. It can't be that problem you're trying to address.

I think stuff like buildPath just shows how the language should be geared more towards compiler optimizations of allocation if performance is a real goal.

The efficient thing to do is to optimize a string concat into a stack allocation (alloca) if it is a throw-away, and just change the stack frame upon return, with some heuristics and alternative execution paths in order to avoid running out of stack space.

E.g.
a(){
    return buildPath(...) ~ "!";
}

Compiles to:

a:
   call buildPath(...)
   alloca(size_to_endof_path_returned_by_buildPath+1)
   *someaddr = '!'
   return (stackbufferstart,length)


buildPath:
   stackbuffer=alloca(sum_of_lengths)
   copy...
   return tuple(stackbufferstart,length)

Reply via email to