mozilla / pluotsorbet

[ARCHIVED] PluotSorbet is a J2ME-compatible virtual machine written in JavaScript.
GNU General Public License v2.0
240 stars 46 forks source link

UTF_8_Reader.read is expensive #306

Closed mykmelez closed 10 years ago

mykmelez commented 10 years ago

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).

1022ms 137 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I
837ms 45121 com/sun/cldc/i18n/j2me/UTF_8_Reader.getByteOfCurrentChar.(IZ)I

We should optimize this method.

marco-c commented 10 years ago

getByteOfCurrentChar is called by read for each character, so probably optimizing read involves optimizing both functions.

marco-c commented 10 years ago

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).

marco-c commented 10 years ago

After #312, this doesn't show up in profiles.

mykmelez commented 10 years ago

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"

marco-c commented 10 years ago

On desktop: 29ms 89 com/sun/cldc/i18n/j2me/UTF_8_Reader.read.([CII)I

marco-c commented 10 years ago

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

marco-c commented 10 years ago

Fixed by #343.