Skip to main content
areohbee
Legend
January 10, 2011
Question

Anybody ever benchmarked lua string ops?

  • January 10, 2011
  • 1 reply
  • 1367 views

Or have reference to benchmarks?

Some of my plugins are unbearably slow. One of the things that concerns me is the speed of string operations.

I'd also be interested in performance of non-string ops, so I can write more efficient plugins.

R

This topic has been closed for replies.

1 reply

johnrellis
Legend
January 10, 2011

Based on my (very) light reading about the Lua implementation, I'd guess that Lua string operations are roughly the same cost as Java string operations. There are two components to the cost: doing the byte manipulations, and the amortized cost of garbage-collecting the strings later.  Unlike Java, Lua needs to hash each string into a global string table, but the incremental cost of that is likely smaller than you think for many apps, since tests for equality take a single instruction, and the hashing can reduce additional storage allocations.   Also, I'd guess that the Lua garbage collector is not as efficient as a modern Java GC, but that's just an educated guess.

johnrellis
Legend
January 10, 2011

You might consider profiling your plugins using the function Debug.profileFunc() from my debugging toolkit (free, of course):

http://www.johnrellis.com/lightroom/debugging-toolkit.htm

This is an elapsed-time profiler, which is generally more useful than a CPU-time profiler.   Because it imposes a non-trivial overhead on each profiled function, start profiling higher-level functions and then drill down into the bigger hogs.

One thing I've found is that a number of the SDK API functions appear to call LrTasks.yield() (or equivalent), and this seems to impose a minimum overhead of at least 10 - 20 ms.   Doesn't seem like much until you discover you're calling it hundreds or thousands of times.

areohbee
areohbeeAuthor
Legend
January 10, 2011

Thanks John,

I will give the debugging toolkit a closer look - theres a lot there :-)

Rob