-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improve performance and clean up the preprocessor #353
Conversation
Testing on larger inputs seem to show that the preprocessor is handling about 14MB/s. (For comparison, the largest |
Closes #342 |
Adopt a systematic and uniform format for the code of the preprocessor Document that given style Add a dune rule so that `dune fmt` reformats the preprocessor accordingly (when `ex` is available)
Use the name `print_directive`, to be consistent with the rest of the printing functions
OCaml needs directives to recover the real positions of any preprocessed source, so preprocessors must output a directive at the very beginning of their outputs
Change the interface of the preprocessor so that it outputs its result into a formatter rather than a string Propagate the change all the way down, so that: - the whole output is generated in a single buffer when the target is a `string`, or directly on `stdout` in the case of `gospel pps`, - `print` becomes tail recursive.
Ensure that `collapse_spaces` is tail recursive so that it does not overflow the stack when running on large inputs That requires an extra list reversal, unfortunately
Updated so that all |
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.
Great, thank you!
This PR reworks the preprocessor by:
In a bit more details, the performance gains are obtained by changing the interface of the preprocessor so that it outputs its result into a formatter rather than a string and propagating the change all the way down, so that:
string
, or directly onstdout
in the case ofgospel pps
,print
becomes tail recursive.Using the example mentioned in #336 (test run in CI, so the performance may vary depending on load...), we go from:
to: