grocy-android
grocy-android copied to clipboard
TextBottomSheet performs heavy synchronous work on UI thread (causing potential jank)
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:
- multiple split() and substring operations
- repeated replaceAll() calls (regex engine; expensive)
- 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.