-
Notifications
You must be signed in to change notification settings - Fork 44
Improve the performance of the Kore parser #2296
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
Conversation
space
and stringParserToIdParser
Lexer functionsUsing Text instead of String reduces peak memory use by 43% and total allocation by 24%. Never use String.
Text.readFile fileName | ||
& liftIO | ||
& clockSomethingIO "Reading the input file" |
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.
@ttuegel Why are these the other way round now?
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.
I changed it from ($)
to (&)
so that the action (Text.readFile
) would appear before the wrappers.
I made some changes to your parser performance pull request which reduce the memory use significantly. (For some reason we were still using String. Never use String.) I would like you to try a few more things:
|
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.
Please remove the redundant look-ahead, and then we can merge this.
Text.readFile fileName | ||
& liftIO | ||
& clockSomethingIO "Reading the input file" |
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.
I changed it from ($)
to (&)
so that the action (Text.readFile
) would appear before the wrappers.
kore/src/Kore/Parser/Lexer.hs
Outdated
(genericId, _) <- Parser.match | ||
$ (Parser.satisfy isFirstChar <?> "first identifier character") | ||
>> Parser.takeWhileP (Just "identifier character") isBodyChar |
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.
I think this is easier to read:
(genericId, _) <- Parser.match | |
$ (Parser.satisfy isFirstChar <?> "first identifier character") | |
>> Parser.takeWhileP (Just "identifier character") isBodyChar | |
(genericId, _) <- Parser.match $ do | |
_ <- Parser.satisfy isFirstChar <?> "first identifier character" | |
_ <- Parser.takeWhileP (Just "identifier character") isBodyChar | |
pure () |
kore/src/Kore/Parser/Lexer.hs
Outdated
then do | ||
skipChar '\\' | ||
(c :) <$> parseIdRaw KeywordsPermitted | ||
then fst <$> Parser.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.
Using match
here makes the look-ahead (above) redundant.
* Inline some primitive parsers * Kore.Parser.Lexer: Remove unused primitive parsers * Run Parser over Text, not String Using Text instead of String reduces peak memory use by 43% and total allocation by 24%. Never use String. Co-authored-by: Thomas Tuegel <[email protected]>
Fixes #2189
Review checklist
The author performs the actions on the checklist. The reviewer evaluates the work and checks the boxes as they are completed.