-
Notifications
You must be signed in to change notification settings - Fork 83
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
Explicitly copy token sequences to avoid sharing input #495
Conversation
The way forward here is to first bring up to date the nix stuff that allows us to observe effects of such changes on dependent packages. I will do it soon. Once that is done we will be able to make an informed decision. |
023eab1
to
982c07c
Compare
Here are the results of benchmark before (old) and after (new) the changes for 3 packages (
While the impact is sometimes negligible, in certain cases it is quite noticeable (notably in the parsers from |
Thanks for sorting out the benchmarks! I had completely overlooked that I agree the impact appears to be large enough that we probably should give people a choice. I propose adding two newtype wrappers In a future major release we could change the default behaviour to What do you think? Shall I update the PR along those lines? |
This sounds good, please go ahead. |
I added |
4933ce2
to
11ae3d7
Compare
11ae3d7
to
3b2aed5
Compare
Thanks! |
Closes #492
As mentioned in the issue, we can avoid leaking memory retaining the input in memory by explicitly copying token sequences as we read them.
The performance implications of adding an explicit
copy
totakeN_
andtakeWhile_
are as follows:takeWhileP
family of basic combinators end up consuming a lot more memory (since previously they didn't need to allocate the result buffer) and time (due to thecopy
call).decimal
(octal
etc) family of combinators are about 40% slower and consume about twice as much memory.many
) have either stayed the same or got slightly (up to 10%) faster.Sadly we don't have any real-world benchmarks (or do we?) so it's hard to tell if this would have any significant impact in practice.
Raw benchmark results
This PR: memory speed
Master: memory speed