Skip to content

refactor(cli/unstable): print progress bar when value and max are changed #6664

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

timreichen
Copy link
Contributor

This PR decodes buffers in tests and compares them to strings for easier comprehension.
It adds getters and setters for value and max which call #print() when the value changes and also recalculates unit and rate when max changes.

@timreichen timreichen requested a review from kt3k as a code owner May 21, 2025 09:11
@github-actions github-actions bot added the cli label May 21, 2025
@timreichen timreichen changed the title refactor(unstable/cli): print progress bar when value and max are changed refactor(cli/unstable): print progress bar when value and max are changed May 21, 2025
Copy link

codecov bot commented May 21, 2025

Codecov Report

Attention: Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.71%. Comparing base (e10c71a) to head (8b4110f).

Files with missing lines Patch % Lines
cli/unstable_progress_bar.ts 96.55% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6664   +/-   ##
=======================================
  Coverage   94.71%   94.71%           
=======================================
  Files         567      567           
  Lines       46778    46799   +21     
  Branches     6582     6585    +3     
=======================================
+ Hits        44305    44326   +21     
  Misses       2431     2431           
  Partials       42       42           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@BlackAsLight
Copy link
Contributor

I don't see the point of calling the #print function every time the values are updated. If value is updated a lot then that can lead to a lot of unnecessary prints.

@timreichen
Copy link
Contributor Author

I don't see the point of calling the #print function every time the values are updated. If value is updated a lot then that can lead to a lot of unnecessary prints.

I wouldn't say these prints are unnecessary. If there is a lot of progress, I think it is beneficial to see that reflected on the progress bar more than every second, no?

@BlackAsLight
Copy link
Contributor

I don't see the point of calling the #print function every time the values are updated. If value is updated a lot then that can lead to a lot of unnecessary prints.

I wouldn't say these prints are unnecessary. If there is a lot of progress, I think it is beneficial to see that reflected on the progress bar more than every second, no?

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

@timreichen
Copy link
Contributor Author

I don't see the point of calling the #print function every time the values are updated. If value is updated a lot then that can lead to a lot of unnecessary prints.

I wouldn't say these prints are unnecessary. If there is a lot of progress, I think it is beneficial to see that reflected on the progress bar more than every second, no?

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

I updated the PR so it checks every 100ms for updates. That way there is a new print every 100ms at most and only on changes while maintaining a mandatory print every second.

@@ -162,8 +162,14 @@ const UNIT_RATE_MAP = new Map<Unit, number>([
* await bar.stop();
*/
export class ProgressBar {
#hasUpdate = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using throttle from @std/async/unstable-throttle to throttle the too many calls? That has no delay when the print call is not throttled.

constructor(...) {
  ...
  this.#throttledPrint = throttle(this.#print, 100)
}

set value(...) {
  ...
  this.#throttledPrint()
}

@kt3k
Copy link
Member

kt3k commented May 26, 2025

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

What would be the maximum reasonable number of re-rendering in a second?

@BlackAsLight
Copy link
Contributor

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

What would be the maximum reasonable number of re-rendering in a second?

Idk, but I think it would be better to leave that up to the user to decide. Looking at the docs, I could have sworn there was an option for them to control the frequency of the updates, but that doesn't seem to be the case.

I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down.

@timreichen
Copy link
Contributor Author

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

What would be the maximum reasonable number of re-rendering in a second?

Idk, but I think it would be better to leave that up to the user to decide. Looking at the docs, I could have sworn there was an option for them to control the frequency of the updates, but that doesn't seem to be the case.

I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down.

No. I very likely could be updating value 100x a second. That is a lot of wasted prints.

What would be the maximum reasonable number of re-rendering in a second?

Idk, but I think it would be better to leave that up to the user to decide. Looking at the docs, I could have sworn there was an option for them to control the frequency of the updates, but that doesn't seem to be the case.

I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down.

Not sure if we should advertise to use the fmt function for such cases in the first place. It is meant to format the output after all, not explicitly for delta calculations.

@kt3k
Copy link
Member

kt3k commented May 26, 2025

I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down.

I see the point, but it feels weird that we can't update frequently to keep the delta calculation correct..

How about splitting the printing of progress bar and the calculation of delta of the value?

@timreichen
Copy link
Contributor Author

I think an inconsistent update interval though could give the effect that the program is having lag spikes and any "delta" values that are introduced or manually calculated via the formatter option can have big jumps up and down.

I see the point, but it feels weird that we can't update frequently to keep the delta calculation correct..

How about splitting the printing of progress bar and the calculation of delta of the value?

Another option would be to provide delta calculations as properties. cli-progress and progress do this.

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

Successfully merging this pull request may close these issues.

3 participants