Zauber Paracelsus

  • Archive
  • RSS

Performance Test: Phlox vs Mono

I was doing some performance tests with some of my code, by measuring how long it takes different methods to complete a particular task a few thousand times.

Now, LSL has more performance constraints than most programming languages, since it is compiled to bytecode and run in a VM.

I had written a bit of code to see if a particular character in a string was a valid hexadecimal digit, as part of a function to check and see if an input string was a valid UUID key, and wrote a lazy method for it.  Then I decided to see if a more complex method would run faster:


Lazy Method:
Calls llSubStringIndex, which iterates over the input string ‘test’ and reports the index number of the first instance of the string ‘s’ that it finds.

if(llSubStringIndex(test,s) == -1)


Ugly Method:
A bunch of OR’ed comparisons, put inside of a ( ) with a ! preceding it to reverse the result to false.

if(!(s==”0” || s==”1” || s==”2” || s==”3” || s==”4” || s==”5” || s==”6” || s==”7” || s==”8” || s==”9” || s==”a” || s==”b” || s==”c” || s==”d” || s==”e” || s==”f”))

For the test, I ran the UUID-checker function in a loop 5000 times.  In each iteration, the hexadecimal checking would be done 32 times, for a total of 160,000 times.  When I started the test, I had expected the lazy method to be less efficient, but the results were surprising:
Average completion time (3 tests):
  • Lazy Method: 2.89 seconds
  • Ugly Method: 6.65 seconds
The Ugly method takes close to 3 times longer to complete.  This test, by the way, was done under Phlox, the script engine at InWorldz.  Curious about the performance differences, I decided to test it with Second Life’s mono engine.  So, I got the same setup going, and performed the testing on the region Mythos, which is a quiet sim that typically has no lag.  And then I waited for it to complete… and waited… and waited… and about a minute and a half later it completed.
Here are the test results, but because they took so long I chose not to run multiple tests for each method.
  • Lazy Method: 104.43 seconds (1 minute, 44 seconds)
  • Ugly Method: 118.61 seconds (1 minute, 58 seconds)
In this one, the scripts were two orders of magnitude slower, though the performance difference between the two was not as great, being a matter of very slower vs. slightly more slower.
For the next test, I decided to do another comparison of a method from within the same UUID-validation function, comparing the performance between a group of OR’ed comparisons and list traversal via llListFindList.  This part is used to check the characters at index numbers 8, 13, 18, and 23 on the input string, to make sure that they are dash symbols.
Here is Method A:
if(llListFindList(test2, [i]) == -1)
And Method B:
if(i==8||i==13||i==18||i==23)
Here is the first test, under Phlox.  Like before, 5000 iterations, called 32 times per iteration, and the test is repeated three times and the results averaged:
  • Method A: 0.167 seconds
  • Method B: 2.442 seconds
Surprisingly, the list traversal was substantially faster than the OR’ed comparisons. So, that brings us to the Mono test in Second Life.  The tests for the Method A were on a somewhat more reasonable timeframe, so I took the average of 3 tests with it.  For Method B, however, it took substantially longer for one test.  And, not only that, but it failed to complete at all on subsequent tests, so it just has the results of one test:
  • Method A: 7.45 seconds
  • Method B: 94.03 seconds (1 minute, 34 seconds)
Again, the difference in performance here is substantial.  Method A is much faster than Method B under both Phlox and Mono, but again: the tests take a much longer  time to complete under Mono.
With how great the performance differences are between Phlox and Mono, you would think that Phlox was compiling scripts to native code or something.  Though, really it isn’t: Phlox is just compiling scripts to a highly-optimized bytecode format, executed in a fast virtual machine.
And Mono?  It’s the open source implementation of the .Net Framework.  Both Mono and .Net are massive beasts, meant to accommodate a wide-variety of programming languages, most of them being object-oriented.  And this is reflected upon the bytecode format they share.
Linden Lab has been moving towards trying to limit scripts in some fashion for years in order to reduce lag and simulator memory usage.  But as Phlox proves, you can do a lot better by writing optimized code.  But at this point, Linden Lab will need to do what InWorldz did, and rewrite their script engine.

And I hope they do so, because it would go a long ways towards improving Second Life.  I won’t hold my breath, though.
    • #Phlox
    • #InWorldz
    • #Scripting
  • 1 year ago
  • 2
  • Comments
  • Permalink
  • Share
    Tweet

2 Notes/ Hide

  1. sorornishi likes this
  2. sorornishi reblogged this from zauberparacelsus
  3. zauberparacelsus posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →

About

Avatar

Pages

  • Lord of Maelstrom
  • Google+
  • Twitter
  • DeviantArt
  • FurAffinity

Me, Elsewhere

Following

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr