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

Improve performance of progress bars under high concurrency #208

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

ajalt
Copy link
Owner

@ajalt ajalt commented Aug 18, 2024

Keeping track of progress history was taking a lot of CPU load if updates were happening very frequently.

@aSemy suggested an improvement in #204 (comment), and this PR goes further:

Instead of keeping a list with an entry for each call to update, we instead keep a fixed size list, and overwrite the last entry if it was very recent. We only look at the first and last entries to calculate speed, so there's no need to keep every entry.

Benchmark                        Mode  Cnt      Score      Error  Units
JmhBenchmark.benchmarkCurrent    avgt    3  34931.106 ± 1299.242  ns/op
JmhBenchmark.benchmarkAsemy      avgt    3   5474.108 ±  634.242  ns/op
JmhBenchmark.benchmarkFixedList  avgt    3    176.047 ±   53.293  ns/op

This change is a 350x speedup on the benchmarks I ran, which seems fast enough.

Fixes #207

@ajalt ajalt enabled auto-merge (squash) August 18, 2024 18:42
@ajalt ajalt merged commit f4c9daa into master Aug 18, 2024
4 checks passed
@ajalt ajalt deleted the optimize-progress-history branch August 18, 2024 18:59
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.

Progress bar CPU usage is high under very high concurrency
1 participant