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

Poor performance of long typing animation #820

Open
jcubic opened this issue Sep 11, 2022 · 7 comments
Open

Poor performance of long typing animation #820

jcubic opened this issue Sep 11, 2022 · 7 comments
Labels
Milestone

Comments

@jcubic
Copy link
Owner

jcubic commented Sep 11, 2022

Issue summary

The longer the animation the slower it become

Expected behavior

The animation should be fast no matter how long, if using 0 as delay

Actual behavior

Animation slows down

Steps to reproduce

  1. Open Gaiman Playground
  2. Change echo result["def"] with echo* result["def"], 0

Additional notes

There is a need for some kind of optimization the longer function is split_equal that needs to be executed on each interval.

A possible solution is using an array as a prompt, and the CMD will assume that it's already partitioned and it may be faster to process since you will not need to use interate_formatting.

@jcubic jcubic added the Bug label Sep 11, 2022
@jcubic jcubic added this to the 2.35.0 milestone Sep 11, 2022
@jcubic
Copy link
Owner Author

jcubic commented Nov 13, 2022

split_equal actually is pretty fast, the real problem is that $.terminal.substring take longer and longer when the string becomes longer and you need to extract element far in the string.

@Pratyush-Nirwan
Copy link

can any one suggest me a work around for this?

@jcubic
Copy link
Owner Author

jcubic commented Nov 24, 2022

@Pratyush-Nirwan there are no solution to fix the issue yet, sorry. Unless you can use smaller strings.

@Pratyush-Nirwan
Copy link

ohh thats sad

@jcubic jcubic modified the milestones: 2.35.0, 2.36.0 Dec 12, 2022
@jcubic
Copy link
Owner Author

jcubic commented Mar 8, 2023

Just realized that maybe I can split a long string into chunks (lines) and process them one by one. It will speed up the animation.

@jcubic
Copy link
Owner Author

jcubic commented Apr 2, 2023

This is a difficult problem, the typing animation already uses partition to split the string into characters with optional formatting. But the draw prompt function (in cmd plugin) calls split_equal on each string (on each added character) and the longer the string the slowest the call. On my machine with ~3000 characters, it took about 50ms which is a lot of you have an animation with 0 delays.

I've optimized split_equal a bit, but this doesn't make much difference.

The only solution I see is to add some method to CMD plugin to allow to add of a single character to the prompt, this will make it possible to ignore the whole draw_prompt function.

jcubic added a commit that referenced this issue Apr 2, 2023
@jcubic jcubic modified the milestones: 2.36.0, 2.37.0 May 19, 2023
@jcubic
Copy link
Owner Author

jcubic commented Dec 30, 2023

Now the lines are split and printed individually on the terminal. This improves the performance of long animations. But still, it slows down when using delay: 0 and long lines.

I leave this open maybe I will come up to speed this even further.

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

No branches or pull requests

2 participants