I've got a couple of questions for someone familiar with the GDScript compiler internals in 3.x.

var i := some_integer()
var s := some_string()

var a := str(i) + " and " + s
var b := "%d and %s" % [i, s]
var c := "{i} and {s}".format({"i": i, "s": s})

Is there any difference in speed between the computation of a, b and c? Is any inlining of format strings performed by the compiler?

6 days later

Is there any difference in speed between the computation of a, b and c?

I'd recommend microbenchmarking it on your own :) Make sure to do this with the project exported in release mode (Export with Debug unchecked in the export file dialog).

You can use OS.get_ticks_usec() for this purpose and a loop such as for i in 100000 (100000 iterations).

Is any inlining of format strings performed by the compiler?

Not that I know of.

I've done just that, and yes, unfortunately it seems that concatenation is faster. Additionally, the release build didn't provide any huge performance leap, so it does indeed look like there's no inlining.

Release

  • concat: 73306
  • template: 145868
  • format: 337335

Debug

  • concat: 78750
  • template: 148896
  • format: 343763

(these are all in microseconds, lower is better; they're averages of 10x200000 computations)

2 years later