-
Notifications
You must be signed in to change notification settings - Fork 107
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
Optimisation of subsequence #490
Comments
(As a note - your implementation has |
Good catch, I've updated the repo and the description of the ticket |
This looks impressive! Shall we keep both or replace the existing one? /cc @ChickenProp, @ocharles (and any other who wants to vote, feel free!) |
It certainly makes sense to me! |
Replace makes sense to me, I can't immediately think of a downside. Oh, but I'd suggest double-checking the shrink behavior. Right now I suspect it can shrink to include things that weren't in the original sublist (e.g. if the original (Quick edit: oh, and |
@ChickenProp Thank you very much for these suggestions, I'll implement them over the week-end. If you have more ideas regarding how to test the behaviour of |
So the test I think I'd write would probably be to take both a generated value and its shrink tree from |
Hi @moodmosaic! I would like to upstream an optimisation to
subsequence
.At present time,
subsequence
is implement as such:filterM (const bool_) xs
Which we can interpret as "Traverse the whole list and at each element, perform a random boolean generation". This is quite expensive as random generation happens for every element, and is thus unguarded.
Here is an alternative:
We can generate a random Word64 that will act as a bitfield, and iterate on it with our list. Each time we encounter a 1, then we keep the element at this index in our list. If we encounter one or multiple 0, we drop them (which is quite efficient, as for instance five successive 0s are dropped once and not five times).
Then we advance either one step (if we found a 1) or as many 0s we had found, and keep going until there are no bits left in our list.
If the Word64 was not enough, we generate one when to retrieve another random list of 1s and 0s.
Considering the average size of random subsequences, this becomes very cheap because we get 1 random operation, perhaps 2, in most cases.
Here are exerpts of the benchmark:
You can run the benchmarks manually at: https://github.com/Kleidukos/subsequence-bench/. They also contain comparisons with QuickCheck, both baseline and improved.
The text was updated successfully, but these errors were encountered: