From: Sascha H. <sa...@xm...> - 2009-09-20 22:16:46
|
Hello Jacob, thank you for your great analysis and question. You are absolutely right. As you can see, we are trying to mimic a JVM as close as possible. While we think that the performance is fine for most use cases, some use cases (like yours) can actually perform much worse when being cross-compiled with XMLVM. Therefore, one of our current tasks is to look at converting our stack-bases model to a register-based one, so that languages like Objective-C can benefit. However, we are still in the planning stage of this and I cannot give you any deadlines. Would this be something you are interested in contributing to or do you have any other ideas? Thank you // Sascha On Sun, Sep 20, 2009 at 11:29 PM, Jacob Nordfalk <jac...@gm...>wrote: > Hi, > > I am considering porting an image manipulation program in Java to iPhone > using XMLVM. > > However, code such as > > public byte[] xxx(byte[] rgb) { > > for (int i = 0; i<rgb.length; i+=3) { > rgb[i] += 1; > rgb[i+1]/=2; > rgb[i+2]/=2; > } > > return rgb; > } > > seems to run 20 times slower than JIT-enabled Java when compiling xmlvm > generated objective-C. > > When I looked at the code I understood why - the generated objective-C is > something like 26 lines > per line of Java (here below is for the line: rgb[i+1]/=2). > > > - (NSMutableArray*) optimize___byte_ARRAYTYPE :(NSMutableArray*)n1 > { > XMLVMElem _stack[4]; > XMLVMElem _locals[5]; > int _sp = 0; > XMLVMElem _op1, _op2, _op3; > ... > > *// rgb[i+1]/=2;* > _stack[_sp++].o = _locals[1].o; > _op1.i = _locals[4].i; > _stack[_sp++].i = _op1.i; > _stack[_sp++].i = 1; > _op2.i = _stack[--_sp].i; > _op1.i = _stack[--_sp].i; > _stack[_sp++].i = _op1.i + _op2.i; > _op1 = _stack[_sp - 2]; > _op2 = _stack[_sp - 1]; > _stack[_sp++] = _op1; > _stack[_sp++] = _op2; > _op1.i = _stack[--_sp].i; > _op2.o = _stack[--_sp].o; > _stack[_sp++].i = [[_op2.o objectAtIndex: _op1.i] intValue]; > _stack[_sp++].i = 2; > _op2.i = _stack[--_sp].i; > _op1.i = _stack[--_sp].i; > _stack[_sp++].i = _op1.i / _op2.i; > _op1.i = _stack[--_sp].i; > _stack[_sp++].i = (int) (_op1.i & 0xFF); > _op1.i = _stack[--_sp].i; > _op2.i = _stack[--_sp].i; > _op3.o = _stack[--_sp].o; > [_op3.o replaceObjectAtIndex: _op2.i withObject: [NSNumber > numberWithInt: _op1.i]]; > > > Now, I understand that the speed factor 20 is becaurse XMLVM is emulating > the stack-based JVM in Objective-C, > but I as I have really LOT of array manipulation code I am asking you: > > > Do you have any advice or ideas on how to make Java code using simple array > manipulations run relatively fast on the iPhone ? > > > > Thanks you, > Jacob Nordfalk > > -- > Jacob Nordfalk > एस्पेरान्तो के हो? http://www.esperanto.org.np/. > Memoraĵoj de KEF -. http://kef.saluton.dk/memorajoj/ > > > ------------------------------------------------------------------------------ > Come build with us! The BlackBerry® Developer Conference in SF, CA > is the only developer event you need to attend this year. Jumpstart your > developing skills, take BlackBerry mobile applications to market and stay > ahead of the curve. Join us from November 9-12, 2009. Register now! > http://p.sf.net/sfu/devconf > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > |