Closed mykmelez closed 10 years ago
getByteOfCurrentChar is called by read for each character, so probably optimizing read involves optimizing both functions.
UTF_8_Reader is reading the InputStream one byte at a time. To optimize it we may implement it in JS, but we'd need to keep some Java code to read from the InputStream (ideally we would read the whole content in a variable and pass it to a JS native that does the work). Here we may be able to use util.decodeUtf8, since UTF_8_Reader uses the UTF8 standard (and not the modified UTF8 that is in the Java class format).
After #312, this doesn't show up in profiles.
I still see this at the top of a firstrun profile:
"11686ms 52 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I" "10928ms 41959 com/sun/cldc/i18n/j2me/UTF_8_Reader.getByteOfCurrentChar.(IZ)I"
On desktop: 29ms 89 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I
I've tried to run the same midlet in the same state (on first run):
Desktop: 1454ms 100 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I
Mobile: 46282ms 101 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I
Fixed by #343.
According to a startup profile of a midlet I'm testing, UTF_8_Reader.read is expensive, with 137 calls taking over a second total (and getByteOfCurrentChar, which *read• calls, is not far behind, although it's called many more times, so its mean time-per-call is much less).
We should optimize this method.