Skip to content

Commit

Permalink
Avoid inferior runloops for autothreading only subs
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jun 6, 2011
1 parent 1019d95 commit bec71af
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 21 deletions.
63 changes: 48 additions & 15 deletions lib/Kernel.cs
Expand Up @@ -969,25 +969,58 @@ public class SubInfo {
if (jun_pivot != -1 && !quiet) {
Variable jct = (jun_pivot == -2 ? named[jun_pivot_n] :
pos[jun_pivot]);
caller.resultSlot = Builtins.AutoThread(jct.Fetch(),
delegate(Variable n) {
if (jun_pivot == -2)
named[jun_pivot_n] = n;
else
pos[jun_pivot] = n;
return Kernel.RunInferior(Binder(
Kernel.GetInferiorRoot(),
outer, sub, pos, named, false, de));
});
th = caller.MakeChild(null, AutoThreadSubSI, Kernel.AnyP);

P6opaque jo = (P6opaque) jct.Fetch();

th.named = named;
th.pos = pos;
th.lex1 = this;
th.lex2 = jun_pivot_n;
th.lex3 = jo.slots[0];
th.lex4 = Kernel.UnboxAny<Variable[]>((P6any)jo.slots[1]);
th.lex5 = outer;
th.lex6 = sub;
th.lex7 = de;
th.lex8 = new Variable[((Variable[])th.lex4).Length];
th.lex9 = jct;

th.lexi0 = jun_pivot;
th.lexi1 = 0;

return th;
}

return th;
}

static SubInfo AutoThreadSubSI = new SubInfo("KERNEL AutoThreadSub", AutoThreadSubC);
static Frame AutoThreadSubC(Frame th) {
Variable[] src = (Variable[]) th.lex4;
Variable[] dst = (Variable[]) th.lex8;
if (th.lexi1 > 0)
dst[th.lexi1 - 1] = (Variable)th.resultSlot;

if (th.lexi1 == dst.Length) {
P6opaque nj = new P6opaque(Kernel.JunctionMO);
nj.slots[0] = th.lex3;
nj.slots[1] = Kernel.BoxRaw(dst, Kernel.ParcelMO);
// restore, in case our caller is using this
if (jun_pivot == -2)
named[jun_pivot_n] = jct;
if (th.lexi0 == -2)
th.named[(string)th.lex2] = (Variable)th.lex9;
else
pos[jun_pivot] = jct;
return caller;
th.pos[th.lexi0] = (Variable)th.lex9;
th.caller.resultSlot = Kernel.NewROScalar(nj);
return th.caller;
}

return th;
if (th.lexi0 == -2)
th.named[(string)th.lex2] = src[th.lexi1++];
else
th.pos[th.lexi0] = src[th.lexi1++];

return ((SubInfo)th.lex1).Binder(th, (Frame)th.lex5, (P6any)th.lex6,
th.pos, th.named, false, (DispatchEnt)th.lex7);
}

public BValue AddHint(string name) {
Expand Down
6 changes: 0 additions & 6 deletions perf/std-20110528.pl6
Expand Up @@ -25,12 +25,6 @@ my %h = (1 => True, 2 => True, 3 => True, 4 => True, 5 => True);
my %h2 = (:a, :b, :c, :d, :e);

bench '|||', 1000000, sub () { 1|2|3|4|5 };
#bench 'any(,,)', 1000000, sub () { any(1,2,3,4,5) };
#bench 'any(..)', 10000, sub () { any(1..5) };
bench '3 == any(,,)', 1000000, sub () { ( 3 == 1|2|3|4|5 ) ?? True !! False };
bench 'grep 3 equiv', 100000, sub () { ( grep 3, 1,2,3,4,5 ) ?? True !! False };
bench 'hash equiv', 100000, sub () { ( %h{3} ) ?? True !! False };
#bench 'eq any (str)', 1000000, sub () { ( "a" eq any("a","b","c","d","e") ) ?? True !! False };
#bench 'hash equiv (str)', 100000, sub () { ( %h2{"a"} ) ?? True !! False };
bench 'onlysub($j)', 100000, sub () { onlysub($j) };
bench '$j.abs', 100000, sub () { $j.abs };

0 comments on commit bec71af

Please sign in to comment.