Skip to content
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

Filter-rewriting 2: rewrite harder #3795

Closed
4 of 7 tasks
Zac-HD opened this issue Nov 19, 2023 · 0 comments · Fixed by #3898
Closed
4 of 7 tasks

Filter-rewriting 2: rewrite harder #3795

Zac-HD opened this issue Nov 19, 2023 · 0 comments · Fixed by #3898
Labels
enhancement it's not broken, but we want it to be better performance go faster! use less memory!

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Nov 19, 2023

#2701 proposed "rewriting" filters in simple cases, i.e. modifying the strategies to satisfy the condition by construction rather than rejection sampling. We shipped this for numeric comparisons, as well as some string methods and float properties like isnan, and it's been working well!

Following #3780, we'd like a way to do filter-rewriting for length filters.

  • starting with partial(min_len, x) for the min_len and max_len functions in filtering.py
  • as an extension, using AST analysis to cover e.g. lambda ls: 0 < len(ls) <= 10 - in this case we'll want to apply the rewrite for efficiency, and apply the predicate as a filter in case the name len has been rebound in the enclosing scope.
  • support st.lists(...).map(some_collection_type), in order to handle st.sets(), st.binary(), st.dictionaries(), and similar user-defined strategies (including .map(tuple), which is returned by st.from_type(tuple[T, ...])).
    • it's probably better to handle this in ListStrategy.map than in MappedStrategy.filter? Gonna be an inelegant hack either way, but the results should be worth it.

There have also been a variety of further filtering extensions proposed in older issues, which I'm listing here in case someone would like to implement one of them. Note however that they're lower priority, so unless someone has explicitly volunteered I'll close this issue when the length filters are done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement it's not broken, but we want it to be better performance go faster! use less memory!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant