andreasgal/j2me.js — pull request #341 by mykmelez (2014-09-25 20:25:47+00:00)
Title: optimize Graphics.drawRegion, Image.class.getField, Math.min

This is a bit of a grab bag from a profile I did of a particular interaction with a midlet:

1. *Graphics.drawRegion* just does a null check and then calls the *Graphics.renderRegion* native, and the former is the only caller of the latter, so 2f1c44a replaces the *Graphics.renderRegion* native with a *Graphics.drawRegion* override.
2. *Graphics.drawRegion* calls *Image.class.getField*, which does potentially expensive loops over arrays of fields, so b23336b implements a field cache similar to the method cache @marco-c implemented earlier. That roughly doubles the speed of the method:

> "8312ms 16401 javax/microedition/lcdui/Graphics.drawRegion.(Ljavax/microedition/lcdui/Image;IIIIIIII)V"
> "4673ms 16401 javax/microedition/lcdui/Graphics.drawRegion.(Ljavax/microedition/lcdui/Image;IIIIIIII)V"

3. *Math.min* showed up in the profile, mostly because it gets called a lot. Overriding it with a native in e1a5499 roughly doubles its performance:
> "1056ms 23482 java/lang/Math.min.(II)I"
> "431ms 23486 java/lang/Math.min.(II)I"