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

Performance of textarea #301

Open
leejack1000 opened this issue Dec 5, 2022 · 6 comments
Open

Performance of textarea #301

leejack1000 opened this issue Dec 5, 2022 · 6 comments

Comments

@leejack1000
Copy link

Can the performance of textarea be optimized?
If I typed texts in textarea, it take a lot of cpu resources, and getting lag for a while.

@maaslalani
Copy link
Member

Hey @leejack1000, this is something we are looking into improving at some point. We want to use a rope implementation to reduce memory usage and speed up the textarea.

@leejack1000
Copy link
Author

Thanks @maaslalani, it's glad to hear this. Looking forward to seeing the results soon.

@mrusme
Copy link

mrusme commented Jan 2, 2023

@leejack1000 just in case you're looking for a quickfix to this, here's what I'm doing:

I have borrowed the code from this PR so that I can use the PlaceOverlay function in my project. Then I went ahead and called the View function that calls all the other .View() functions, from within the UI's Update function, and stored the output in a Model variable. Inside the View function (that calls all other View functions) I then check whether the textarea is focused and, if so, only call its View function and no other components' View function. I then utilize the PlaceOverlay function to place the updated textarea view on top of the cached view of the whole screen.

Long story short, this way it's possible to get pretty decent performance out of the textarea without the need to modify any bubbles or bubble tea itself. As soon as the texarea becomes active, only the cached view of the whole screen is being used and only the textarea gets .View() calls. It's sort of a poor-man's partial UI refresh.

@mrusme
Copy link

mrusme commented Jan 9, 2023

Having made the code public today I can now link to what I've described above, in case anyone comes across the same issue and is looking for workaround.

@leejack1000
Copy link
Author

Having made the code public today I can now link to what I've described above, in case anyone comes across the same issue and is looking for workaround.

Thank you for sharing.

@mikelorant
Copy link
Contributor

All the pieces are now in place for this issue to be sorted out, just need some merges and dependencies updated.

Just to reiterate the performance improvements to expect, here is a comment I made on another issue.

Just did some very quick benchmarks of my own app with pasting 1000 characters (14 lines) into a textarea of 72 characters wide:

Before: 42s
After: 3s

For context, no optimisations to my own app code at all. All these performance increases came from:

  • bubbles
  • lipgloss
  • reflow
  • uniseg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants