Skip to content

Fix ANR caused by exponential recursion in getIterator() - #270

Open
cursor[bot] wants to merge 1 commit into
mainfrom
seer/applicationnotresponding-background-anr-4uii4u
Open

cursor[bot] wants to merge 1 commit into
mainfrom
seer/applicationnotresponding-background-anr-4uii4u

Conversation

@cursor

@cursor cursor Bot commented Sep 5, 2026

Copy link
Copy Markdown

Summary

This PR fixes an Application Not Responding (ANR) issue caused by naive exponential recursion in the MainFragment.getIterator() method. The method was computing Fibonacci-style values using recursive calls to getIterator(n-1) + getIterator(n-2), resulting in approximately 2^44 function calls when invoked with n=44. This computation was executed on the main thread via an OkHttp callback, blocking the UI and triggering ANRs.

The fix replaces the exponential recursive implementation with an iterative approach that computes the same result in O(n) time instead of O(2^n), eliminating the performance issue entirely.

This pull request was triggered by a Seer handoff from Sentry.

Fixes ANDROID-NA

Open in Web Open in Cursor 

Replace naive recursive Fibonacci computation with iterative approach to
avoid ~2^44 recursive calls blocking the main thread. The iterative
implementation computes the same result in O(n) time instead of O(2^n).

Fixes ANDROID-NA (https://demo.sentry.io/issues/7713986262/)
@cursor
cursor Bot requested a review from sdzhong as a code owner September 5, 2026 22:10
@sentry

sentry Bot commented Sep 5, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (21c77a4) to head (0f69a74).

Files with missing lines Patch % Lines
.../example/vu/android/empowerplant/MainFragment.java 0.00% 8 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #270   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         16      16           
  Lines        883     890    +7     
  Branches      67      68    +1     
=====================================
- Misses       883     890    +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

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