LanguageDev / Yoakke

A collection of libraries for implementing compilers in .NET.
https://languagedev.github.io/Yoakke/
Apache License 2.0
143 stars 7 forks source link

Performance & Benchmarks #149

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

Problem

Yoakke, unfortunately, turns out to have significant performance issues (compared to Antlr, for example). They are:

  1. Inefficient ParseResult and related types. Making it efficient may boost it to 10x, but it's still not enough
  2. A lot of nested interfaces. Every call on token stream is 5+ nested calls.

However, the parsing and lexing algos look to be fine. At least, I didn't get past 2., so cannot say for sure.

WhiteBlackGoose commented 2 years ago

Initial results:

Method Mean Error StdDev
Parse 49.920 us 1.1544 us 3.2936 us
Lex 3.713 us 0.0708 us 0.1494 us
WhiteBlackGoose commented 2 years ago

image Parser - [2022-06-14 20-26-04].zip

WhiteBlackGoose commented 2 years ago

Replaced ParseError's binary OR with return first:

Method Mean Error StdDev
Parse 15.655 us 0.3817 us 1.0641 us
Lex 2.825 us 0.0562 us 0.0998 us
WhiteBlackGoose commented 2 years ago
Removed creating a dictionary on ParseError Method Mean Error StdDev
Parse 7.425 us 0.1222 us 0.1143 us
Lex 2.752 us 0.0516 us 0.0552 us
WhiteBlackGoose commented 2 years ago

image Parser - [2022-06-14 23-12-46].zip

WhiteBlackGoose commented 2 years ago

Warning: this is wrong result, because it dysfunctions

Replaced `public static ParseResult operator (ParseResult first, ParseResult second)withreturn first.IsOk ? first.Ok : first.Error;` Method Mean Error StdDev
Parse 919.3 ns 18.34 ns 25.71 ns
Lex 3,779.2 ns 73.81 ns 121.27 ns

But it looks wrong, so gotta make it functionally correct

WhiteBlackGoose commented 2 years ago

For AngouriMath these optimizations have these impacts

Method Mean Error StdDev Median
ParseEasy OOB 11.61 ms 0.440 ms 1.298 ms 11.10 ms
ParseEasy Optim 1.143 ms 0.0510 ms 0.1371 ms 1.131 ms
ParseEasy Antlr 0.039 ms
ParseHard OOB 155.05 ms 9.570 ms 28.217 ms 146.27 ms
ParseHard Optim 69.306 ms 2.8647 ms 7.8420 ms 66.660 ms
ParseHard Antlr 4.4 ms
WhiteBlackGoose commented 2 years ago

Warning: no merge! The Result type is intentionally broken!

kant2002 commented 11 months ago

@WhiteBlackGoose i'm new maintainer of the Yoakke, so if you still (after such long time) want to continue exploration of Yoakke performance, I'm here for you.