Skip to content

Conversation

@MaximilianAlgehed
Copy link
Collaborator

@MaximilianAlgehed MaximilianAlgehed commented Nov 6, 2025

The normal Gen monad always splits the seed when doing >>=. This is for very good reasons - it lets you write generators that generate infinite data to the left of a >>= and let's your generators be very lazy!

A traditional GenT m a implementation would inherit this splitting behaviour in order to let you keep writing infinite and lazy things to the left of >>= on the GenT m level. Now, the thing to realize about this is that unless your code is very carefully written to avoid it this means you're going to end up with unnecessary >>=s and thus unnecessary splits.

To get around this issue of unnecessary splits we introduce a threading GenT implementation here that sacrifices letting you do infinite (and to some extent lazy) structures to the left of >>= on the GenT m level, but doesn't prohibit you from doing so on the Gen level.

This drastically reduces the number of seed splits while still letting you write lazy and infinite generators in Gen land by being a little bit more careful. It works great for constrained-generators in particular, which has a tendency to be strict and by design avoids inifinte values.

@MaximilianAlgehed MaximilianAlgehed marked this pull request as draft November 6, 2025 14:32
@MaximilianAlgehed MaximilianAlgehed changed the title Try to make Gen fast by choosing when we're strict and when we lazily split the seed Speed up generation by threading seeds instead of splitting them in non-Gen part of GenT Nov 13, 2025
@MaximilianAlgehed MaximilianAlgehed marked this pull request as ready for review November 13, 2025 14:44
@Soupstraw Soupstraw requested a review from lehins November 20, 2025 10:21
@Soupstraw
Copy link
Contributor

@lehins would be the perfect person to review this

Copy link
Member

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes total sense!
LGTM 👍

@MaximilianAlgehed MaximilianAlgehed merged commit 1e1e1b4 into master Nov 21, 2025
9 checks passed
@MaximilianAlgehed MaximilianAlgehed deleted the fast-genT branch November 21, 2025 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants