grocy-android icon indicating copy to clipboard operation
grocy-android copied to clipboard

TextBottomSheet performs heavy synchronous work on UI thread (causing potential jank)

Open nbd-boss opened this issue 4 weeks ago • 0 comments

Description:

In TextBottomSheet.java, the onCreateView() method synchronously calls ResUtil.getRawText() and FormattedTextView.setText() on the UI thread.

1. getRawText() does synchronous file I/O

getRawText() reads raw resources line by line using BufferedReader.readLine() and appends them to a StringBuilder. If the text resource is large, this synchronous I/O will block the UI thread.

2. setText() performs heavy CPU work

setText() includes:

  1. multiple split() and substring operations
  2. repeated replaceAll() calls (regex engine; expensive)
  3. dynamically adding many Views through addView() For large text content or many highlight patterns, these operations become CPU-intensive and run entirely on the main thread, causing visible jank or frame drops.

3. Android official best practices

According to Android performance guidelines, both file I/O and heavy computation should not run on the main/UI thread. These tasks should ideally be moved to a background thread before updating the UI.

nbd-boss avatar Nov 28 '25 02:11 nbd-boss