Skip to content

Throttle stderr progress reporting and other improvements#203

Open
rkr35 wants to merge 3 commits intogoogle:mainfrom
rkr35:pu-perf
Open

Throttle stderr progress reporting and other improvements#203
rkr35 wants to merge 3 commits intogoogle:mainfrom
rkr35:pu-perf

Conversation

@rkr35
Copy link
Collaborator

@rkr35 rkr35 commented Feb 4, 2026

See individual commit messages.

rkr35 added 2 commits February 3, 2026 18:55
Update `libhoth_progress_stderr_func` to only output to stderr when
significant progress (at least 1%) has been made, or when at the
start/end of an operation.

Previously, progress updates could occur as frequently as every byte,
leading to excessive syscalls and stderr noise. This change improves
performance by ensuring updates are sparse while still providing useful
feedback to the user.

Changes:
- Add `last_reported_numerator` to track reporting state.
- Implement a 1% threshold for reporting updates.
- Ensure 0% and 100% are always reported.
Changes:
- Cache `isatty` check: Move `isatty(STDERR_FILENO)` from the update
  function to `init`. This avoids making a system call on every progress
  update, reducing overhead in the hot path.
- Rename parameters: Change `numerator`/`denominator` to
  `current`/`total` to better reflect their semantic meaning in a
  progress context.
- Fix time math: Adjust `ts_subtract` logic to prevent `tv_nsec` from
  being outside the standard range. Previously, equal nanoseconds
  triggered an unnecessary borrow, resulting in an invalid `tv_nsec`
  value of 10^9.
- Standardize units: Switch from kB (implied 1000) to KiB (1024) to
  match standard binary prefixes used in system tools. Usage of `PRIu64`
  ensures portability across platforms.
- Reduce visual jitter: Display remaining time as integer seconds rather
  than fractional to make the output more stable and readable.
- Fix visual artifacts: Append the ANSI clear-line sequence `\033[K` to
  the output. This ensures that if a progress line is shorter than the
  previous one, no stale characters remain on the screen.
@rkr35 rkr35 marked this pull request as ready for review February 4, 2026 07:02
Add tests for the progress reporting functionality:

- Initialization and basic output format.
- Throttling of progress updates (only printing on >1% change or total
  completion).
- Throughput calculation and estimated time remaining.
- Edge cases such as zero total, zero start time, and non-TTY
  environments.
- Handling of large transfer sizes (multi-GiB).

```
bazel test //protocol:progress_test
```
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.

2 participants