Skip to content

_onDraw() performs heavy blocking operations on the UI thread (severe jank & ANR risk) #858

@nbd-boss

Description

@nbd-boss

Hello, I found that _onDraw() inside BRouterMapView performs a large amount of heavy work directly on the UI thread, including:

● Calling Thread.sleep() inside UI rendering (200–500ms)

● Creating a large Bitmap every frame

● Filling large pixel arrays

● Iterating over large sets (openSet, nogoList, wpList)

● Running business logic inside onDraw

● Triggering invalidate() every frame → infinite redraw loop

These behaviors may cause:

  • Long UI thread blocking
  • Extremely low frame rate
  • Frozen UI / unresponsive touch events
  • High CPU load
  • Potential ANR on many devices

According to Android guidelines, onDraw() must stay lightweight and should not contain:

  • Sleeping
  • Heavy CPU operations
  • Bitmap allocation
  • Business logic
  • Infinite redraw loops

Suggestions:

  1. Move all routing calculations and pixel generation to a background thread
  2. Keep onDraw() strictly for drawing only
  3. Pass results from worker threads to the View
  4. Only draw already-prepared bitmap on UI to avoid blocking

This is a structural issue, and fixing it would significantly improve UI responsiveness and stability.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions