fix: avoid unnecessary recursion if not needed#3611
Merged
ianna merged 11 commits intoscikit-hep:mainfrom Aug 26, 2025
Merged
Conversation
9 tasks
Codecov Report❌ Patch coverage is
Additional details and impacted files
🚀 New features to boost your workflow:
|
ikrommyd
reviewed
Aug 20, 2025
Co-authored-by: Iason Krommydas <iason.krom@gmail.com>
ikrommyd
reviewed
Aug 20, 2025
Collaborator
|
Fixes scikit-hep/coffea#1364 too |
This was referenced Aug 20, 2025
Closed
Collaborator
|
Fixes scikit-hep/coffea#1389 |
ianna
reviewed
Aug 23, 2025
ianna
requested changes
Aug 23, 2025
Member
ianna
left a comment
There was a problem hiding this comment.
@pfackeldey - looks great! Thank you! Just a minor comment - I personally find the name of the flag confusing. Why not wrap_generator? Thanks
ianna
approved these changes
Aug 26, 2025
Member
ianna
left a comment
There was a problem hiding this comment.
@pfackeldey - Great! Thanks for addressing the comments!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR avoids unnecessary recursion for VirtualArray transformations in case they are no-ops. Otherwise in rare cases we may descend down the call stack hell and discover circles of hell that even Dante Alighieri didn't know about...
There are no infinity recursions here; but because Python has a limit on the recursion depth we try to avoid them as much as possible. This wouldn't be an issue if Python would have had tail recursion optimization (but it doesn't). This issue is a language limitation...
To completely avoid recursion we could use a FIFO stack to track all operations and run them in order in the materialization, but that turns out to be harder to implement and will be very much unreadable, harder to maintain, and harder to reason about, which is why this PR doesn't do that now.
If anyone runs into this ever again (and that should be really weird edge cases), one can always increase Pythons recursion depth limit with
sys.setrecursionlimit(some_large_value). (Or we can revise the stack approach.)