-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make atto parser faster than the scala parser combinator one #586
base: master
Are you sure you want to change the base?
Conversation
private val sexagesimal: Parser[Int] = int.filter(x => x >= 0 && x < 60) | ||
private val decimal: Parser[Int] = int.filter(x => x >= 0) | ||
private val literal: Parser[String] = takeWhile1(_ >= ' ') | ||
private def oneOrTwoDigitsPositiveInt: Parser[Int] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the optimization that makes it much faster
|
||
private val sexagesimal: Parser[Int] = oneOrTwoDigitsPositiveInt.filter(x => x >= 0 && x < 60) | ||
|
||
private val literal: Parser[String] = takeWhile1(x => x != ' ' && x != '-') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a correctness fix as things like mon-fri
were failing previously
sepBy1(b, comma) | ||
.filter(_.size > 1) | ||
.map(values => SeveralNode.fromSeq[F](values.toList).get) | ||
sepBy(b, comma) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were actually checking the size several times, now it's done a single time
case ParseResult.Done(_, result) => Right(result) | ||
case ParseResult.Fail("", _, _) => Left(ExprTooShort) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a correctness fix : a too short expression was not detected as such
556f6b3
to
bf3f9cb
Compare
@@ -166,8 +184,9 @@ package object atto { | |||
} yield CronExpr(sec, min, hour, day, month, weekDay) | |||
|
|||
def parse(e: String): Either[Error, CronExpr] = | |||
(cron.parseOnly(e): @unchecked) match { | |||
(phrase(cron).parseOnly(e): @unchecked) match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a correctness fix : it ensure the string is parsed entirely
bf3f9cb
to
5d08ad3
Compare
For some reason, I'd rather replace the scala parser combinator implementation with something else.
I read that the atto parser is not the default one because it's slower than the current one ( #468 (comment) )
This PR fixes some correctness issues and makes it faster than the current one, it may be enough to allow the switch?
Here are my numbers regarding performances