Three-Month Investigation of an Intermittent Mobile UI Flicker

    An intermittent mobile UI flicker persisted for three months because the team initially treated it as a rendering or performance issue. By reconstructing state transitions, tracking view updates, and correlating asynchronous tasks with page instances, the team found that multiple callbacks were competing to control the same UI. The fix combined a unified page state model, centralized rendering, asynchronous task cancellation, and targeted verification with the help of an intelligent coding tool.

    1. Background: Why an “Intermittent Flicker” Took Three Months to Diagnose

    In November 2025, users reported that a specific page in the application occasionally flickered during a particular interaction sequence.

    Visually, the problem appeared straightforward:

    • Part of the page would suddenly become brighter or darker during navigation.
    • Some controls would briefly disappear and then reappear.
    • The flicker usually lasted less than a second.
    • Normal interaction could not reliably reproduce it.
    • The occurrence rate varied across devices, operating system versions, and runtime environments.

    The initial assumption was that this was an animation issue, a rendering glitch, or a performance problem on certain devices. However, flickering does not necessarily mean that drawing failed. It can also indicate that multiple states became active in sequence within a very short period.

    For example, a page might go through the following sequence:

    1. The page enters a loading state.
    2. A data request returns.
    3. The page switches to content display.
    4. An asynchronous task modifies part of the state again.
    5. Animation or transition logic is triggered again.
    6. The layout system performs another calculation.
    7. The interface eventually returns to its expected state.

    Without clear timing constraints between these steps, users may see an intermediate frame rather than the final state.

    The issue lasted three months not because the team lacked possible fixes, but because it lacked an evidence chain that could consistently narrow down the cause.

    2. Early Investigation: Significant Effort Without a Conclusion

    The initial investigation focused on several areas.

    2.1 Repeatedly Adjusting Animation Parameters

    The team first tried reducing animation durations, disabling transition animations, changing easing curves, and adding delays in different page lifecycle callbacks.

    These changes sometimes reduced the frequency of the flicker, but they did not solve the underlying problem. Animation parameters only change the time window in which the issue appears. If the root cause is an incorrect state update order, a delay makes the failure harder to reproduce rather than eliminating it.

    2.2 Suspecting Device Performance or Operating System Versions

    Because the issue was more visible on some lower-performance devices, the investigation also examined:

    • Whether the main thread was blocked.
    • Whether the page was triggering excessive layout work.
    • Whether image resources were too large.
    • Whether memory usage experienced short-term spikes.
    • Whether rendering behavior differed across operating system versions.

    These checks were useful, but they mainly answered whether the page was sufficiently smooth. They did not explain why a control disappeared and then returned.

    A performance problem and a state consistency problem can both appear as flickering, but they require very different investigation paths.

    2.3 Adding Local Conditions to Display Logic

    The team also added guard conditions in several places, such as:

    1. if isPageVisible && dataReady {
    2. showContent()
    3. }

    This approach could reduce the issue temporarily. However, if isPageVisible and dataReady are maintained by separate asynchronous flows, intermediate combinations can still occur:

    1. T1: isPageVisible = true
    2. T2: dataReady = false
    3. T3: isPageVisible = false
    4. T4: dataReady = true

    As the page moves through these states, any intermediate state may be rendered.

    Adding isolated checks cannot replace a unified state model.

    3. The Breakthrough: Reconstructing What Happened in Each Frame

    The investigation changed direction when the team stopped looking only at the visible result and began recording the complete sequence of state changes.

    3.1 Building a Unified Event Log

    The team added structured logging to the page. Each record included at least:

    • A timestamp.
    • The page instance identifier.
    • The current thread.
    • The lifecycle event.
    • The data state.
    • The visibility state.
    • The animation state.
    • The layout state.
    • The source that triggered the change.
    • The values before and after the state change.

    A simplified example looked like this:

    1. func trace(_ event: String, state: PageState) {
    2. let timestamp = Date().timeIntervalSince1970
    3. let thread = Thread.isMainThread ? "main" : "background"
    4. print("""
    5. [PageTrace]
    6. time=\(timestamp)
    7. thread=\(thread)
    8. event=\(event)
    9. state=\(state)
    10. """)
    11. }

    The value of logging was not the number of entries. It was consistency. Information from different modules had to be placed on the same timeline so the team could determine which component changed the state first and whether the change occurred on the main thread.

    3.2 Tracking the Display State of Critical Views

    Business state alone was not enough because business state does not always equal visual state. The team also tracked:

    • Opacity.
    • Whether the view participated in layout.
    • Whether the view participated in drawing.
    • Its current position and size.
    • Its parent-child hierarchy.
    • The source of its most recent update.

    This made it possible to distinguish between three easily confused situations:

    1. The view still existed, but its opacity had changed.
    2. The view had been removed from the layout tree.
    3. The view existed and was visible but was covered by another layer.

    All three may look like a disappearing view, but they require completely different fixes.

    3.3 Comparing Normal and Abnormal Paths

    The team collected logs from both normal and abnormal flows and compared the order of events rather than only the final state.

    The abnormal path eventually revealed a repeated update:

    1. Page appears
    2. → Loading starts
    3. → Data returns
    4. → Content is displayed
    5. → A page transition callback fires again
    6. → Loading state is written again
    7. → Content is briefly hidden
    8. → An asynchronous callback restores the content

    This showed that the problem was not a random failure in low-level rendering. Two independent state sources were competing to control the same visual result.

    4. Root Cause: Multiple Asynchronous Sources Updating the UI

    Further investigation reduced the problem to three design flaws.

    4.1 No Single Source of Truth for Page State

    The page’s display state was affected by multiple modules:

    • Page lifecycle events.
    • Network completion callbacks.
    • User interactions.
    • Transition animation callbacks.
    • Cache restoration logic.
    • Asynchronous task cancellation and retry logic.

    These modules could modify view properties directly, but they did not go through a unified state machine.

    When multiple modules directly modify isHidden, alpha, or layout properties, any callback can overwrite a decision made by another callback moments earlier.

    4.2 Asynchronous Task Lifetimes Were Not Bound to Page Instances

    Some requests and delayed tasks continued executing after the page had been left. After the old page was destroyed or recreated, callbacks from old tasks could still return and attempt to update the current interface.

    This type of issue is highly intermittent because it depends on:

    • Network response speed.
    • User interaction speed.
    • The timing of page transitions.
    • Whether task cancellation happened in time.
    • The current workload on the main thread.

    Without a page instance identifier, it is easy to mistake this for a random state change within a single page.

    4.3 Loading and Content Visibility Were Not Mutually Exclusive

    The original implementation controlled the loading indicator, content area, and error message as separate views. Each view had its own visibility condition.

    This meant that multiple views could satisfy their display conditions simultaneously, or none of them could. More importantly, different callbacks could update them at different times, producing transient invalid combinations.

    A more reliable approach is to define a finite set of page states:

    1. idle
    2. loading
    3. content
    4. empty
    5. error

    A single rendering function can then determine the final appearance of all controls:

    1. func render(state: PageState) {
    2. switch state {
    3. case .idle:
    4. renderIdle()
    5. case .loading:
    6. renderLoading()
    7. case .content:
    8. renderContent()
    9. case .empty:
    10. renderEmpty()
    11. case .error:
    12. renderError()
    13. }
    14. }

    This prevents different modules from modifying individual controls independently.

    5. Converging on a Fix in Two Days: Where the Intelligent Coding Tool Helped

    Once the team had sufficient logs and code context, it introduced an intelligent coding tool to assist with the analysis. The tool did not directly guess the answer. Its main value was improving the speed of information organization, call-path analysis, and verification.

    Day 1: Mapping the Global Call Relationships

    The first step was not to ask the tool to immediately generate a fix. Instead, it was used to read and organize the code:

    • Find every location that modified the target view properties.
    • List variables related to page state.
    • Identify all asynchronous callbacks.
    • Map lifecycle and transition call chains.
    • Find rendering functions that might execute more than once.
    • Compare page creation, destruction, and recreation flows.

    This brought state modification points that had been scattered across multiple files into a single call relationship map.

    The most important discovery was that the same display property had multiple write sources, and those sources had no unified execution order.

    Day 2: Generating and Verifying a Minimal Fix

    After the root cause was clear, the team avoided a large-scale refactor and implemented three focused changes.

    Step 1: Unify Page State

    Multiple Boolean variables were replaced with one explicit page state, preventing contradictory combinations.

    Step 2: Centralize Rendering

    All visual properties were updated through a single rendering entry point. Business callbacks submitted state changes but no longer modified views directly.

    Step 3: Bind Asynchronous Tasks to the Page Instance

    Old tasks were cancelled when the page was left, the instance was destroyed, or a new request began. Callbacks also verified that the page instance was still valid.

    The logic was similar to:

    1. guard taskOwnerID == currentPageID else {
    2. return
    3. }
    4. guard !isPageClosing else {
    5. return
    6. }
    7. updateState(.content)

    After the changes, the team stress-tested repeated entry, rapid back navigation, consecutive refreshes, weak network conditions, and rapid page switching. The main focus was whether state events still appeared as out-of-order writes.

    6. Reusable Lessons from the Investigation

    6.1 Do Not Automatically Treat Flickering as a Performance Problem

    Flickering can result from:

    • State competition.
    • Out-of-order asynchronous callbacks.
    • Repeated page rendering.
    • Overlapping animations.
    • Layer occlusion.
    • Layout instability.
    • Placeholder-to-content transitions during resource loading.
    • Incomplete lifecycle handling.

    Before changing animation parameters or optimizing performance, determine which category of problem is actually occurring.

    6.2 Build a Timeline Before Discussing the Root Cause

    Intermittent issues should be converted into sortable event sequences whenever possible. At minimum, the investigation should establish:

    1. Who changed what
    2. At what time
    3. From which state
    4. To which state
    5. On which thread
    6. For which page instance

    Without a timeline, the team is forced to rely on guesses. With one, many “random” failures become deterministic state transition errors.

    6.3 Design Logs to Test Hypotheses

    More logs are not necessarily better. Every log entry should answer a specific question:

    • Are there multiple write sources?
    • Is a callback executing more than once?
    • Is a callback from an old page still active?
    • Is a thread switch occurring?
    • Are states being written out of order?
    • Is rendering happening repeatedly within the same frame?

    Logs designed around hypotheses are more effective than indiscriminately printing large numbers of variables.

    6.4 Separate Business State from Visual State

    The business layer should determine the page’s current state. The rendering layer should determine how that state appears.

    When these responsibilities are mixed, network callbacks and lifecycle callbacks tend to manipulate views directly, creating an implicit state machine that is difficult to maintain.

    6.5 Use Intelligent Tools to Accelerate Analysis, Not Replace Engineering Judgment

    Intelligent tools are well suited to:

    • Searching across files.
    • Organizing call chains.
    • Identifying duplicated logic.
    • Summarizing logs.
    • Drafting repair plans.
    • Completing test cases.
    • Generating risk checklists.

    However, developers must still decide whether a code change is appropriate, how broad it should be, and whether it could introduce new lifecycle problems in the actual runtime environment.

    7. Follow-Up Improvements: Turning a One-Time Fix into a Long-Term Capability

    To prevent similar issues, the team introduced several engineering measures:

    1. Standardize the page state model
      Use explicit state enumerations for complex pages to reduce ambiguity caused by combinations of Boolean variables.

    2. Define asynchronous task cancellation rules
      Old tasks must be cancelled when a page exits, a request is replaced, or a component is destroyed.

    3. Add state transition assertions
      Record transitions that should not occur so they can be detected earlier during testing.

    4. Retain logs for abnormal paths
      Correlate page instances, task identifiers, and state changes to support production incident analysis.

    5. Add timing-focused tests
      Test not only normal network conditions and ordinary taps, but also rapid interaction, repeated entry, weak networks, delayed tasks, and page destruction.

    6. Create a minimal reproduction project
      Reduce the problem to three components—page, state, and asynchronous tasks—so it can be verified independently of the larger application.

    Conclusion

    This three-month mobile UI flicker was not ultimately fixed by a magic animation parameter. The issue was gradually isolated through complete event logging, explicit state modeling, asynchronous lifecycle management, and a minimal code change.

    The intelligent coding tool consumed approximately $110 in compute resources over two days and significantly reduced the time required for code reading, call-relationship analysis, and fix verification. However, the decisive factor was still the engineering process: translate a visual symptom into state changes, convert an intermittent failure into a verifiable timeline, and resolve the state competition with the smallest effective change.

    The most important lesson is simple:

    Do not focus only on what flashed on the screen. Trace which states were competing for control of the interface immediately before that frame.