I might need to optimize this XD
-
If I have understood it correctly: yield uses fibers, foreach uses yield. So try to swap a few well chosen foreach loops for classic for loops and see what happens.
Wrong is evil and must be defeated. - Jeff Ello
I'm not using any foreach loops. I've already optimized the VM itself to within an inch of its life
Real programmers use butterflies
-
I'm not using any foreach loops. I've already optimized the VM itself to within an inch of its life
Real programmers use butterflies
How about Linq?
Wrong is evil and must be defeated. - Jeff Ello
-
How about Linq?
Wrong is evil and must be defeated. - Jeff Ello
I thought the goal was to speed this up?
Real programmers use butterflies
-
L0001: jmp L0002, L0010, L0021, L0029, L0040, L0050, L0059, L0070, L0082, L0092, L0101, L0109, L0115, L0121, L0133, L0142, L0149, L0157, L0167, L0174, L0185, L0190, L0198, L0209, L0213, L0219, L0223, L0233, L0241, L0247, L0256, L0264, L0272, L0278, L0285, L0292, L0297, L0302, L0306, L0311, L0315, L0319, L0323, L0327, L0331, L0335, L0339, L0343, L0347, L0352, L0357, L0361, L0366, L0371, L0375, L0380, L0384, L0389, L0393, L0398, L0402, L0407, L0412, L0416, L0421, L0426, L0430, L0435, L0440, L0444, L0449, L0453, L0458, L0492, L0499, L0506, L0513, L0520, L0527, L0537, L0546, L0554, L0561, L0568, L0574, L0583, L0591, L0598, L0606, L0616, L0625, L0633, L0640, L0647, L0656, L0665, L0671, L0681, L0690, L0696, L0702, L0708, L0716, L0728, L0753, L0768, L0773
Each JMP operand spawns a fiber (basically a thread). I haven't counted how many are spawned here, but 70-80 or so? I think maybe this code is a bit heavy handed. This is just to match a (quite complicated) regular expression
Real programmers use butterflies
Lounge?
-
I thought the goal was to speed this up?
Real programmers use butterflies
I didn't tell you to use it, I'm just looking for problems. :-)
Wrong is evil and must be defeated. - Jeff Ello
-
Lounge?
Yes, this is the Lounge.
Real programmers use butterflies
-
I didn't tell you to use it, I'm just looking for problems. :-)
Wrong is evil and must be defeated. - Jeff Ello
Look away. Here's almost all of it. The stuff you don't see is very thin
public static int Run(int[][] prog,LexContext input)
{
input.EnsureStarted();
int i,match=-1;
_Fiber[] currentFibers, nextFibers, tmp;
int currentFiberCount=0, nextFiberCount=0;
int[] pc;
// position in input
int sp=0;
// stores our captured input
var sb = new StringBuilder(64);
int[] saved, matched;
saved = new int[2];
currentFibers = new _Fiber[prog.Length];
nextFibers = new _Fiber[prog.Length];
_EnqueueFiber(ref currentFiberCount, ref currentFibers, new _Fiber(prog,0, saved), 0);
matched = null;
var cur = -1;
if (LexContext.EndOfInput != input.Current)
{
var ch1 = unchecked((char)input.Current);
if (char.IsHighSurrogate(ch1))
{
if (-1 == input.Advance())
throw new ExpectingException("Expecting low surrogate in unicode stream. The input source is corrupt or not valid Unicode", input.Line, input.Column, input.Position, input.FileOrUrl);
var ch2 = unchecked((char)input.Current);
cur = char.ConvertToUtf32(ch1, ch2);
}
else
cur = ch1;} while(0
-
Lounge?
In the sticky post at the top: 2. Technical discussions are welcome...[^]
Wrong is evil and must be defeated. - Jeff Ello
-
Look away. Here's almost all of it. The stuff you don't see is very thin
public static int Run(int[][] prog,LexContext input)
{
input.EnsureStarted();
int i,match=-1;
_Fiber[] currentFibers, nextFibers, tmp;
int currentFiberCount=0, nextFiberCount=0;
int[] pc;
// position in input
int sp=0;
// stores our captured input
var sb = new StringBuilder(64);
int[] saved, matched;
saved = new int[2];
currentFibers = new _Fiber[prog.Length];
nextFibers = new _Fiber[prog.Length];
_EnqueueFiber(ref currentFiberCount, ref currentFibers, new _Fiber(prog,0, saved), 0);
matched = null;
var cur = -1;
if (LexContext.EndOfInput != input.Current)
{
var ch1 = unchecked((char)input.Current);
if (char.IsHighSurrogate(ch1))
{
if (-1 == input.Advance())
throw new ExpectingException("Expecting low surrogate in unicode stream. The input source is corrupt or not valid Unicode", input.Line, input.Column, input.Position, input.FileOrUrl);
var ch2 = unchecked((char)input.Current);
cur = char.ConvertToUtf32(ch1, ch2);
}
else
cur = ch1;} while(0
Oh, no wonder then, you're doing it on purpose... :laugh:
Wrong is evil and must be defeated. - Jeff Ello
-
Oh, no wonder then, you're doing it on purpose... :laugh:
Wrong is evil and must be defeated. - Jeff Ello
Doing what on purpose? I'm a little slow this morning. :)
Real programmers use butterflies
-
Doing what on purpose? I'm a little slow this morning. :)
Real programmers use butterflies
Spawning loads of fibers. Or is this auto generated code again?
Wrong is evil and must be defeated. - Jeff Ello
-
Spawning loads of fibers. Or is this auto generated code again?
Wrong is evil and must be defeated. - Jeff Ello
Well, it's not on purpose per se. I mean yes, I'm spawning a lot of them, but the idea is to keep as few active or "alive" at one time as possible. when I see a jmp with 3 operands it spawns 2 fibers in addition to a primary fiber. That's what I don't want, since every fiber has to examine the character under the cursor which leads to many examinations of the same character. There's no way to optimize this out because it's rather the point of the fiber running in the first place. Multiple examinations are a byproduct of the NFA algorithm. My goal is simply to reduce/eliminate the amount of jmps and especially the number of operands they have. A pure DFA can run by examining each character only once.
Real programmers use butterflies