Skip to content

fix: avoid unnecessary recursion if not needed#3611

Merged
ianna merged 11 commits intoscikit-hep:mainfrom
pfackeldey:avoid_recursion
Aug 26, 2025
Merged

fix: avoid unnecessary recursion if not needed#3611
ianna merged 11 commits intoscikit-hep:mainfrom
pfackeldey:avoid_recursion

Conversation

@pfackeldey
Copy link
Copy Markdown
Collaborator

@pfackeldey pfackeldey commented Aug 8, 2025

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.)

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 8, 2025

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.49%. Comparing base (b749e49) to head (ae71af6).
⚠️ Report is 398 commits behind head on main.

Files with missing lines Patch % Lines
src/awkward/_nplikes/virtual.py 93.33% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/awkward/_nplikes/array_module.py 95.01% <100.00%> (+8.63%) ⬆️
src/awkward/operations/ak_from_buffers.py 84.33% <ø> (-9.79%) ⬇️
src/awkward/_nplikes/virtual.py 91.19% <93.33%> (ø)

... and 193 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ianna ianna self-requested a review August 14, 2025 15:49
@ianna ianna added the pr-next-release Required for the next release label Aug 14, 2025
Co-authored-by: Iason Krommydas <iason.krom@gmail.com>
@ikrommyd
Copy link
Copy Markdown
Collaborator

Fixes scikit-hep/coffea#1364 too

@ikrommyd
Copy link
Copy Markdown
Collaborator

Fixes scikit-hep/coffea#1389

Copy link
Copy Markdown
Member

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@pfackeldey - looks great! Thank you! Just a minor comment - I personally find the name of the flag confusing. Why not wrap_generator? Thanks

Copy link
Copy Markdown
Member

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@pfackeldey - Great! Thanks for addressing the comments!

@ianna ianna merged commit dbe2ef2 into scikit-hep:main Aug 26, 2025
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-next-release Required for the next release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants