-
Notifications
You must be signed in to change notification settings - Fork 25
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
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
Hi @alonsodomin , it seems you are not active anymore on github and cron4s, any chance you consider discussing about sharing the maintenance of cron4s project? |
hello @mbaechler, thanks for your submitted work and sorry for reviewing this earlier (btw, best way to nudge me into reviewing something is to add me as a reviewer in the PR). Anyway, I'm on and off at Github but definitely more active on other repos than this one. I have no issue on sharing ownership of this repo, it's indeed useful to the community (even though I don't use it as much) and I think it would be great to do a clean up of the library. I'll email you my contact so we can continue the conversation. Regarding the changes addressed in this PR, how confident you feel after this improvements to make Atto the default parser? In my view this should move in that direction but also there should be a period of time in which the scala combinators parser is still available and that users could choose to use it (before finally deleting it from the code). |
Thank you for your answer.
I'm not very confident, right now.
It sounds reasonable. |
in that case, it may be worth moving the atto impl out of the bench code and into a separate module and make the test kit target it to at least ensure that functionality between the two is fully preserved. |
I will do in another commit, do you think we can merge this one? |
5d08ad3
to
fd15deb
Compare
I guess, as it touches a single file that is not a part of any library artifact, I can merge it safely. |
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