Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Sep 26, 2025

sequence_from_generator_preallocate_helper currently requires the genexp's sequence to be a Sequence type. Preallocating is quite nice, we should do it more often!

This PR extends it for cases where the sequence is not a Sequence type but the length is known at compile-time.

This PR was built on top of #19927 , as it doesn't make any sense to implement this optimization without that PR first merged. Separately, we cannot do any realiable IR testing on #19927 without this accompanying PR. You will notice slight differences in the IR test between the 2 branches, those differences indicate that the combination of the 2 PRs works as expected.

BobTheBuidler and others added 14 commits September 25, 2025 20:54
This PR is pretty simple, I just extended get_expr_length to work for a few more obvious cases:

- `builtins.enumerate`
- `builtins.map`
- `builtins.zip`
- `builtins.range`

This PR is ready for review. Are you going to want tests for all of these? I don't want to spend time now until I know for sure.
@BobTheBuidler BobTheBuidler changed the title Non sequence preallocator [mypyc] feat: support non-sequence inputs with known len in sequence_from_generator_preallocate_helper Sep 26, 2025
@BobTheBuidler BobTheBuidler marked this pull request as draft October 1, 2025 17:45
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.

1 participant