Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Optimize Interpreter -> Native / Compiled calls. #1577

Open
mbebenita opened this issue May 22, 2015 · 3 comments
Open

Optimize Interpreter -> Native / Compiled calls. #1577

mbebenita opened this issue May 22, 2015 · 3 comments

Comments

@mbebenita
Copy link
Contributor

Calling natives or compiled methods from the interpreter requires popping arguments off the stack, putting them in an array and then using apply. This is pretty slow and we should optimize calls for the most frequent cases. Below are the frequencies of the most common signature kinds during the startup of my favorite midlet. At the very least, we ought to special case the no argument case, which appears to be the most frequent.

Freq Signature Kinds: [Return Kind, Argument 0 Kind, Argument 1 Kind, ...]
  62 0 
   3 0,0,4,8,4,4 
 382 0,3 
   8 0,4 
   2 0,4,8 
 757 0,8 
  35 0,8,4 
   1 0,8,4,4,8,8,8,8,8,4,4,4,8,0 
  26 0,8,8 
   8 1 
   5 3 
 752 3,3 
 225 3,4 
2200 4 
  12 4,3,4 
  57 4,4 
 103 4,4,4 
   3 4,5 
   1 4,6 
 186 4,8 
 143 4,8,4 
  44 4,8,4,4 
  10 4,8,8 
   4 4,8,8,4,4 
  35 6 
   2 6,6 
   1 6,6,6 
   3 6,7 
   4 6,8,8 
2436 8 
  14 8,3 
   6 8,3,3 
 163 8,4 
   2 8,4,0 
 102 8,4,4 
   2 8,4,4,4 
   8 8,4,8 
  10 8,6 
   4 8,6,4 
 511 8,8 
   1 8,8  
   3 8,8,3 
   7 8,8,4 
  20 8,8,4,0 
   3 8,8,4,0,0 
   3 8,8,4,4 
   6 8,8,4,4,4,4,8 
   1 8,8,4,4,8,8,8,8,8,4,4,4,8,0 
 134 8,8,8 
   3 8,8,8,0 
3394 9 
  16 9,0 
   2 9,1 
 682 9,4 
   4 9,4,0 
  17 9,4,3 
  72 9,4,4 
   1 9,4,4,4 
  86 9,4,4,8 
 238 9,4,4,8,4 
 123 9,4,8 
   2 9,4,8,0 
   2 9,4,8,4,4,8 
   2 9,4,8,4,8 
  16 9,6 
   8 9,6,8 
   3 9,6,8,0 
   5 9,6,8,6 
 807 9,8 
   2 9,8,0 
  26 9,8,4 
  99 9,8,4,4 
   6 9,8,4,4,4,4,8 
   2 9,8,4,4,4,8,8,4 
   2 9,8,4,4,8 
   3 9,8,4,8 
 384 9,8,4,8,4,4 
   1 9,8,6 
 118 9,8,8 
   4 9,8,8,4 
   7 9,8,8,4,4 
   4 9,8,8,4,8 
  25 9,8,8,8 
   4 9,8,8,8,8 
   6 9,8,8,8,8,8
@marco-c marco-c added the perf label May 22, 2015
@marco-c
Copy link
Contributor

marco-c commented May 22, 2015

Aren't we already doing this?

            var argumentSlots = calleeMethodInfo.hasTwoSlotArguments ? -1 : calleeMethodInfo.argumentSlots;
            switch (argumentSlots) {
              case 0:
                returnValue = calleeMethod.call(object);
                break;
              case 1:
                a = stack.pop();
                returnValue = calleeMethod.call(object, a);
                break;
              case 2:
                b = stack.pop();
                a = stack.pop();
                returnValue = calleeMethod.call(object, a, b);
                break;
              case 3:
                c = stack.pop();
                b = stack.pop();
                a = stack.pop();
                returnValue = calleeMethod.call(object, a, b, c);
                break;
              default:
                if (calleeMethodInfo.hasTwoSlotArguments) {
                  frame.popArgumentsInto(calleeMethodInfo, argArray);
                } else {
                  popManyInto(stack, calleeMethodInfo.argumentSlots, argArray);
                }
                var returnValue = calleeMethod.apply(object, argArray);
            }

@mbebenita
Copy link
Contributor Author

Yes. I should have prefixed the issue with, "we need to do this for the new interpreter."

@marco-c
Copy link
Contributor

marco-c commented May 28, 2015

#1605 adds the no-argument fast path.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants