jRuby on Rails - Google App Engine Performance Tip
The process of running jRuby on Rails on Google App Engine is still a bit rough around the edges and I’m discovering new tricks every day. This time, I found how to improve performance of an operation by over 100%.
I was looking at Pager Duty taking unreasonably long to load the home page. Some investigation showed that the bottleneck was loading the list of latencies for the graphs, which are stored as an array of Longs in the Google App Engine Datastore. Particularly, the culprit was the conversion from a Java List to a Ruby Array.
The data comes back from the Datastore as a Java ArrayList. At first, I used:
array = list.to_a
after some experimentation, I instead tried:
array = list.toArray.to_a
Surprisingly, this increased performance of that operation by over 100%!!!
user system total real
list.to_a 1.875000 0.000000 1.875000 ( 1.875000)
list.toArray.to_a 0.916000 0.000000 0.916000 ( 0.916000)
Yes, I agree, it’s strange enough to be reported.
