You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem TextLayoutResult#getLineForOffset is too slow. I looked at source code, linear search is performed in the class SkiaParagraph. It can be optimized by using binary search.
OS version(s) (required for Desktop and iOS issues): macOS 14.0 Beta
OS architecture (x86 or arm64): arm64
JDK (for desktop issues): 17
Sample code
@Composable
funApp() {
val text = remember { "Super long text\n".repeat(10000) }
val scrollState = rememberScrollState()
Box {
BasicTextField(
value = text,
onValueChange = {},
onTextLayout = { textLayoutResult ->val lineOffsets =listOf(0) +"\n".toRegex().findAll(text).map { it.range.endInclusive +1 }
val lineTops = lineOffsets.map { textLayoutResult.getLineTop(textLayoutResult.getLineForOffset(it)) }
println("Done. ${lineTops.size}")
},
modifier =Modifier.fillMaxSize().verticalScroll(scrollState),
)
VerticalScrollbar(
modifier =Modifier.align(Alignment.CenterEnd),
adapter = rememberScrollbarAdapter(scrollState),
)
}
}
Reproduction steps
Run the app
Hangs until some minutes later
Video
N/A
Profiling data
N/A
Additional information
I was implementing line number display and text folding for a TextField. As #3866 is not available yet, I try an alternative using TextLayoutResult#getLineForOffset. Unfortunately, it only works for small number of lines. I wonder if there is a feasible workaround at this moment.
The text was updated successfully, but these errors were encountered:
Describe the problem
TextLayoutResult#getLineForOffset
is too slow. I looked at source code, linear search is performed in the classSkiaParagraph
. It can be optimized by using binary search.Affected platforms
I only tried on Desktop.
If the problem is Android-only, report it in the Jetpack Compose tracker
Versions
Sample code
Reproduction steps
Video
N/A
Profiling data
N/A
Additional information
I was implementing line number display and text folding for a TextField. As #3866 is not available yet, I try an alternative using
TextLayoutResult#getLineForOffset
. Unfortunately, it only works for small number of lines. I wonder if there is a feasible workaround at this moment.The text was updated successfully, but these errors were encountered: