-
Notifications
You must be signed in to change notification settings - Fork 23
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
Remove usages of cons
#5
Comments
Another way would be to have a data structure that can do an O(1) append at the front (e.g. a reversed array). But I think that might be confusing as well... |
@chriseidhof Oh, my local experimental build became much faster by this approach! I'll create branch that we can test that. |
Awesome! I also would think that removing the mutual recursion in functions like |
I have included this approach in the |
Did you push those commits? I can't seem to find them! |
Sorry, I did not include that. 🙇 |
And I apologize that I misunderstood approach of this issue. |
By the way, I just wrote my code in the quickest and dirtiest way possible, I totally think there's a lot of room for writing it in a more functional way. For example, I really don't like the |
Sorry, I found bug on my TryParsecExperiment by making functional test pass, then the duration back to 5.595sec. 😞 |
I'm not sure what exactly changed in your branch, but I'm pretty sure that my change made everything a lot faster! So maybe we should separate the two things so we can clearly see the differences? =) |
Yes, your change made faster. |
I wrote about nn/experiment branch on #10. |
When we use a lot of
cons
(e.g. inmany
) this will slow down the code, because a copy of the array has to be made and inserting at index 0 is O(n).There are a couple of workarounds. The most "brute-force" one would be to rewrite
many
(and other combinators). I'm sorry, the code is quite ugly, but I think many parts can be factored out nicely to keep everything in a functional style. The key trick is to have oneresult
array that's not shared, so the compiler can modify it without making copies.This makes it twice as fast on my machine! I think some other cases are
manyTill
,sepBy1
,count
, etc.The text was updated successfully, but these errors were encountered: