Skip to content

Commit

Permalink
Update #37 Performance updates
Browse files Browse the repository at this point in the history
- just a bit more unrolling pays off
- finally beat both regex benchmarks in ci-tests
- benchmarking will be results posted in #37

Signed-off-by: jrte <jrte.project@gmail.com>
  • Loading branch information
jrte committed Oct 11, 2023
1 parent 122d631 commit f283533
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
60 changes: 33 additions & 27 deletions src/com/characterforming/jrte/engine/Transductor.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ public ITransductor run() throws EffectorException, DomainErrorException {
int token = -1, state = 0, last = -1, signal = 0;
if (this.prologue != null) {
signal = this.prologue.signal();
this.matchMode = MATCH_NONE;
this.prologue = null;
}
Input input = Input.empty;
Expand All @@ -415,7 +414,7 @@ public ITransductor run() throws EffectorException, DomainErrorException {
int pos = input.position;
// get next input token
if (signal > 0) {
pos = input.position;
this.matchMode = MATCH_NONE;
token = signal;
signal = 0;
} else {
Expand All @@ -425,12 +424,12 @@ public ITransductor run() throws EffectorException, DomainErrorException {
token = -1;
break T;
}
pos = input.position;
}
pos = input.position++;
token = 0xff & input.array[pos];
token = 0xff & input.array[input.position++];
}

int action = NIL, mode = this.matchMode;
int action = NIL;
S: do {
switch (this.matchMode) {
// trap runs in (nil* paste*)* effector space
Expand All @@ -441,42 +440,49 @@ public ITransductor run() throws EffectorException, DomainErrorException {
action = Transducer.action(transition);
if (action == PASTE)
this.value.paste((byte)token);
else if (action != NIL)
else if (action != NIL) {
this.metrics.traps[MATCH_NONE][0] += 1;
this.metrics.traps[MATCH_NONE][1] += input.position - pos;
break S;
token = input.position < input.limit
? 0xff & input.array[input.position++]
: -1;
}
if (input.position < input.limit)
token = 0xff & input.array[input.position++];
else
token = -1;
} while (token >= 0);
break;
this.metrics.traps[MATCH_NONE][1] += input.position - pos;
continue I;
// absorb self-referencing (msum,mscan) or sequential (mproduct) transitions with nil effect
case MATCH_SUM:
if (token < SIGNUL)
token = sumTrap(input, token);
token = sumTrap(input, token);
this.metrics.traps[MATCH_SUM][1] += input.position - pos;
if (token >= 0)
this.metrics.traps[MATCH_SUM][0] += 1;
else
continue I;
break;
case MATCH_PRODUCT:
if (token < SIGNUL)
token = productTrap(input, token);
token = productTrap(input, token);
this.metrics.traps[MATCH_PRODUCT][1] += input.position - pos;
if (token >= 0)
this.metrics.traps[MATCH_PRODUCT][0] += 1;
else
continue I;
break;
case MATCH_SCAN:
if (token < SIGNUL)
token = scanTrap(input, token);
token = scanTrap(input, token);
this.metrics.traps[MATCH_SCAN][1] += input.position - pos;
if (token >= 0)
this.metrics.traps[MATCH_SCAN][0] += 1;
else
continue I;
break;
default:
assert false;
break;
}
if (token < 0) {
if (input.position > pos) {
this.metrics.traps[mode][0] += input.position > pos ? 1 : 0;
this.metrics.traps[mode][1] += input.position - pos;
}
continue I;
}
assert this.matchMode == MATCH_NONE;
} while (true);
if (input.position > pos) {
this.metrics.traps[mode][0] += input.position > pos ? 1 : 0;
this.metrics.traps[mode][1] += input.position - pos;
}

// effect action and check for transducer or input stack adjustment
assert this.matchMode == MATCH_NONE;
Expand Down
1 change: 1 addition & 0 deletions src/com/characterforming/jrte/test/FileRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public static void main(final String[] args) {
String sscan = String.format("(%d/%.2f%%):mscan", scan, msc);
System.out.println(String.format("%8.3f mb/s %7.3f nul/kb %16s %16s %20s %17s",
mbps, ekb, snone, ssum, sproduct, sscan));
assert bytes >= 10*blen;
} else {
try (
final FileInputStream isr = new FileInputStream(f);
Expand Down

0 comments on commit f283533

Please sign in to comment.