Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address slow responsiveness in CodeEditText #21

Open
dgmltn opened this issue Jan 25, 2024 · 2 comments
Open

Address slow responsiveness in CodeEditText #21

dgmltn opened this issue Jan 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dgmltn
Copy link

dgmltn commented Jan 25, 2024

Thanks a lot for your contribution to Compose MP!

Have you given any thought to performance? For instance, CodeEditText with the onValueChange -> highlights loop builds a new Highlights object on every keypress. This takes a long time, especially if code is long. But even if code is short, it is still too slow. Here's a video, trying to type "world":

Screen.Recording.2024-01-25.at.12.27.47.mov

One solution is to have a separate coroutine applying color to the new text after it has changed. The coroutine would be cancelled if the text changed again quickly, before the last round of colorization finished. But that's ok!

I might call it like this:

@Composable
fun CodeEditor2(
    code: String,
    onCodeChanged: (String) -> Unit,
    modifier: Modifier = Modifier,
) {
    val highlightBuilder = Highlights
        .Builder(
            language = SyntaxLanguage.JAVASCRIPT,
            theme = SyntaxThemes.darcula(true),
        )
    CodeEditText(
        modifier = modifier,
        code = code,
        onValueChange = onCodeChanged,
        highlightBuilder = highlightBuilder,
        colors = TextFieldDefaults.colors(),
    )
}

and the HighlightBuilder could be used internally, inside CodeEditText. At first I would expect new keys I type to just use a default color, and then after a short delay, their color might change.

@tmaxxdd
Copy link
Member

tmaxxdd commented Jan 27, 2024

@dgmltn Hi 👋

Thank you for such a descriptive issue posted :)

Yes, I know that the performance is not top-notch.

Main focus was put on making this work and next iterations should improve speed.

Thanks again for some code snippets, I will take them into consideration and yes coroutines can help us here :)

@tmaxxdd
Copy link
Member

tmaxxdd commented Aug 11, 2024

Update on that.

I am sorry to say that but I had no time to address this problem.

I think I will redo that once again in next months

@tmaxxdd tmaxxdd added the bug Something isn't working label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants