Skip to content

progress-bar: use dynamic size units#14423

Merged
Mic92 merged 1 commit into
NixOS:masterfrom
MarcelCoding:progress-bar-units
Nov 10, 2025
Merged

progress-bar: use dynamic size units#14423
Mic92 merged 1 commit into
NixOS:masterfrom
MarcelCoding:progress-bar-units

Conversation

@MarcelCoding

Copy link
Copy Markdown
Member

Motivation

I've also implemented the changes from #14364 for the progress bar now.

Although it works, I am not quite happy with it.

If I copy something big from one host to another, the total size will probably be >1GiB. The problem now is that the current progress stays as 0 for way too long because the already transferred bytes are still below 0.1GiB.

2025-10-30_09-54

and after like 10 seconds it looks like that:

2025-10-30_09-59

This problem could be fixed by not displaying the unit only once for a X/X/X GiB block, but instead for every block: X GiB/ X GiB/X GiB.

In the reality, this could look like this: 100KiB/25MiB/1GiB. But I am afraid this could be too verbose.

Maybe the community or maintainers could express some kind of opinion in the direction this should be going.

Also, this could just be a me-problem, because I am expecting that the number is always changing because it was like that till now.

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@xokdvium

Copy link
Copy Markdown
Contributor

In the reality, this could look like this: 100KiB/25MiB/1GiB

I like this in general. If the units are the same we could skip intermediate units though and keep the last one. That would make things less verbose and reduce duplication.

@MarcelCoding

MarcelCoding commented Nov 1, 2025

Copy link
Copy Markdown
Member Author

@xokdvium I've just implemented your suggestion:

2025-11-01_18-15 2025-11-01_18-18

I kind of dislike that it is still kind too quiet. How about adding some kind of spinner like with npm or pnpm that indicates that nix is not frozen and still working?

@xokdvium

xokdvium commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

kind of spinner like with npm or pnpm

Sounds great! That could be a separate PR if you'd like.

Comment thread src/libutil/include/nix/util/util.hh Outdated
throw UsageError("'%s' is not an integer", s);
}

size_t getSizeUnit(int64_t value);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we maybe add an enum for the unit? Something like enum class SizeUnit

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

like its implemented now?

@MarcelCoding MarcelCoding force-pushed the progress-bar-units branch 2 times, most recently from 35e1301 to ba9fd9b Compare November 2, 2025 02:10
Comment thread src/libmain/progress-bar.cc Outdated
Comment thread src/libutil/util.cc Outdated
@MarcelCoding MarcelCoding force-pushed the progress-bar-units branch 2 times, most recently from 5b07a5d to db9a922 Compare November 2, 2025 14:49
Comment thread src/libutil/include/nix/util/util.hh Outdated
Comment thread src/libutil/include/nix/util/util.hh Outdated
Comment thread src/libutil/util.cc Outdated
Comment thread src/libutil/include/nix/util/util.hh Outdated
Comment thread src/libutil/include/nix/util/util.hh Outdated
@MarcelCoding MarcelCoding force-pushed the progress-bar-units branch 2 times, most recently from 958bcb5 to 3a081b6 Compare November 2, 2025 16:11
@Mic92

Mic92 commented Nov 6, 2025

Copy link
Copy Markdown
Member

@xokdvium good to go?

Comment thread src/libutil-tests/util.cc Outdated

@xokdvium xokdvium left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good. Not a huge fan of the amount of duplication, but that can get cleaned up another time.

@MarcelCoding

Copy link
Copy Markdown
Member Author

I've tried to implement it in the first function, but I've failed and just hardcoded the unit in a copy of the function.

@Mic92 Mic92 added this pull request to the merge queue Nov 10, 2025
Merged via the queue into NixOS:master with commit accb564 Nov 10, 2025
16 checks passed
@MarcelCoding MarcelCoding deleted the progress-bar-units branch November 10, 2025 18:18
@xokdvium

Copy link
Copy Markdown
Contributor

Apparently this broke download size rendering. Will be looking into that.

return s;
};

auto renderSizeActivity = [&](ActivityType type, const std::string & itemFmt = "%s") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should have been this:

Suggested change
auto renderSizeActivity = [&](ActivityType type, const std::string & itemFmt = "%s") {
auto renderSizeActivity = [&] [[nodiscard]] (ActivityType type, const std::string & itemFmt = "%s") {

So that the bug below couldn't have been introduced

}

showActivity(actFileTransfer, "%s MiB DL", "%.1f", MiB);
renderSizeActivity(actFileTransfer, "%s DL");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does nothing, since the return value is ignored

xokdvium added a commit that referenced this pull request Nov 25, 2025
This was broken in #14423 accidentally.
Add [[nodiscard]] to prevent such mistakes in the future.
@xokdvium

Copy link
Copy Markdown
Contributor

Fix in #14647

@edolstra edolstra mentioned this pull request Dec 9, 2025
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

Successfully merging this pull request may close these issues.

3 participants