-
Notifications
You must be signed in to change notification settings - Fork 624
Open
Labels
performancego faster! use less memory!go faster! use less memory!
Description
Correct me if I'm wrong here, but it seems like sets
backtracks in a lot of common cases it doesn't need to. The current implementation:
- Generates a list of the requested size;
- backtracks if there are duplicates, and then;
- turns that list into a set.
This means that any time you have duplicates (which could be very often depending on the desired set size and the strategy for contained values) the whole generator gives up. I propose that the better approach would be:
- Generate a list of the requested size (or greater?);
- turn that list into a set;
- check if the set is still an appropriate size.
This would mean that a lot of cases that currently backtrack won't need to, and it also gives us options other than backtracking. E.g., if the resulting set is too large, we could remove some elements, and if it's too small we could add some until we have a big enough set.
Does this make sense? Am I missing something, or would this be a pretty straightforward performance improvement?
Metadata
Metadata
Assignees
Labels
performancego faster! use less memory!go faster! use less memory!