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

Holding key when typing input exhausts render time #961

Closed
ordo-n opened this issue Sep 2, 2024 · 15 comments
Closed

Holding key when typing input exhausts render time #961

ordo-n opened this issue Sep 2, 2024 · 15 comments
Labels
Bug resolved if issue is resolved, it will be open until merge with master

Comments

@ordo-n
Copy link

ordo-n commented Sep 2, 2024

Issue summary

Holding down the "a" key to input "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".... gets progressively slow the longer you hold it down. This is compounded by the more colored text is displayed in the terminal. It slows down dramatically to the point of freezing. I have tested this on several systems fast and slow. The render time in the dev tools is where the lag occurred.

Expected behavior

It should not use so much render time simply to insert characters into the input or when removing characters.

Actual behavior

Very slow, very laggy, freezes

Steps to reproduce

Print colored text to the terminal, the more that's printed the worse it gets
Then hold down the "a" key to insert "aaaaaaaaaaaaaaaa".. into the input and then hold backspace to delete. Both insert and backspace lag.

Browser and OS

Edge, Chrome,

Additional notes

https://jsfiddle.net/p29yh7ja/

@ordo-n ordo-n added the Bug label Sep 2, 2024
@jcubic
Copy link
Owner

jcubic commented Sep 3, 2024 via email

@ordo-n
Copy link
Author

ordo-n commented Sep 3, 2024

I am limiting with outputLimit: 750

But due to my use of color the lag becomes terrible as soon as it reaches that limit. (it's quite bad even on a expensive CPU)

The only way to be lag free is to use outputLimit: 200 (not enough for my use case) or remove color entirely.

Are there any ideas for reducing render time? should the input really re-render the whole terminal (doesn't that seem unnecessary?)

The only other thing that I can think to do is to print raw html with colored spans instead of using the inbuilt coloring (i.e [[;red;]text]

AI has suggested that I use requestAnimationFrame but that hasnt worked for me, in fact it makes the lag worse.

@ordo-n
Copy link
Author

ordo-n commented Sep 3, 2024

Before I go ahead and make changes, would using colored spans instead of the inbuilt coloring increase performance?

Many thanks

@ordo-n ordo-n changed the title Exhausting Render Time Holding key when typing input exhausts render time Sep 3, 2024
@ordo-n
Copy link
Author

ordo-n commented Sep 3, 2024

Using colored spans with raw:true instead of the inbuilt coloring works to reduce the lag quite alot!

@jcubic
Copy link
Owner

jcubic commented Sep 3, 2024

This is really weird, because command line is a different component (jQuery plugin), so what's on the terminal should not affect the interaction with the Command Line.

I need to investigate. Thanks for reporting.

@jcubic
Copy link
Owner

jcubic commented Sep 3, 2024

I did a quick check and what you have is the limitation of the Browser. There are simply way too many DOM nodes on the page. The insert of the character trigger reflow of the whole page. Check this code that use { raw: true } and inserts single and double span

https://codepen.io/jcubic/pen/JjQmqQM

I'm not sure if I can do something about this to not break the library. But maybe something you can do to limit the reflow of the whole page. The performance Tool in Google Chrome says that this a bottleneck even with a single span.

@jcubic
Copy link
Owner

jcubic commented Sep 3, 2024

contain CSS property didn't help. I think that I will need to close this bug. The only thing I can think of that will improve performance is to use Virtual Output. Technique used by React-Window, but this will be a big task to create a feature like this. And this would be tracked as a separate feature. Maybe even for version 3.0 if it will ever happen.

Unless you have other idea how to improve performance.

@ordo-n
Copy link
Author

ordo-n commented Sep 4, 2024

I do not know the code base well enough to be of as much use as I could be but I think that the command input should be independent of the terminal, it shouldn't be so dependant on the rest of the terminal. If it were decoupled the performance would not matter as the input would perform well regardless of how many lines are in the terminal

@jcubic
Copy link
Owner

jcubic commented Sep 4, 2024

Before the virtual window is implemented, you can try using outputLimit: 0 option. It will only display as many lines as there are on the screen, no scrollbar.

@jcubic
Copy link
Owner

jcubic commented Sep 4, 2024

I found the root cause of this delay, when I commented one line the freeze is gone, but that line is there for a reason. I need to investigate if I can somehow get rid of it and don't change the behavior of the library.

@jcubic
Copy link
Owner

jcubic commented Sep 4, 2024

The fix was simpler than I expected, the problem was that in one place I compared width and used the wrong element and the code trigger each time you press a key, and it should only trigger when the terminal width change. This caused a whole page Layout update that took 50ms when a lot of DOM was on the page, enough to freeze the inserting keys.

jcubic added a commit that referenced this issue Sep 4, 2024
@jcubic
Copy link
Owner

jcubic commented Sep 4, 2024

The issue is fixed on a devel branch and will be included in next release.

@ordo-n
Copy link
Author

ordo-n commented Sep 4, 2024

Brilliant news! I'm eager to test the developer branch. I haven't built the project from scratch yet. I do npm install but then the expected function npm run build doesnt appear to exist. Advise please.

@jcubic
Copy link
Owner

jcubic commented Sep 4, 2024

The project use make not npm to build files, but you don't need to build anything. Just clone the repo and change the branch, build files are part of the repo. If you use CDN for your project you don't even need to clone the repo. You can just grab files directly from github

<script src="https://cdn.jsdelivr.net/gh/jcubic/jquery.terminal@devel/js/jquery.terminal.js"></script>

You can also just download the file from github:

https://github.com/jcubic/jquery.terminal/blob/devel/js/jquery.terminal.min.js

@jcubic jcubic added the resolved if issue is resolved, it will be open until merge with master label Sep 5, 2024
@ordo-n
Copy link
Author

ordo-n commented Sep 5, 2024

can confirm it works perfectly

@jcubic jcubic closed this as completed Sep 7, 2024
@github-staff github-staff deleted a comment from maher-nakesh Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug resolved if issue is resolved, it will be open until merge with master
Projects
None yet
Development

No branches or pull requests

2 participants