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
Learn to be lazy with time checks. Don't lock if not threading #197
Learn to be lazy with time checks. Don't lock if not threading #197
Conversation
Codecov Report
@@ Coverage Diff @@
## master #197 +/- ##
==========================================
+ Coverage 95.76% 96.31% +0.54%
==========================================
Files 1 1
Lines 425 488 +63
==========================================
+ Hits 407 470 +63
Misses 18 18
Continue to review full report at Codecov.
|
@test @elapsed(prog_perf(10^7)) < 40*@elapsed(noprog_perf(10^7)) | ||
@test @elapsed(prog_perf(10^7)) < 8*@elapsed(noprog_perf(10^7)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on local tests this could go down to 5, but CI seems closer to 6/7. 8 to be conservative
6d579c7
to
ff28e85
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know all the internal details but this change looks good to me. A nice observation!
ff28e85
to
3b62f41
Compare
I've tested this in the ways I can think might challenge it, including
.. and I haven't seen any bad behavior. Given a few updates on master with new features and no breaking changes to the public API, in a couple of days I'll release 1.6.0 unless anyone disagrees |
Hi @IanButterworth. My sims unfortunately hits on the other end of the spectrum where the step counter counts replicate sim runs each of which has an indeterminate number of time steps and runs a long time. I was calling Should I try multiple progress meters now? Or maybe there would be a flag to restore the old behavior? |
Ok! Yes, let's add a flag to restore the old behavior. Would you happen to have a MWE that I can test and add to the test suite? |
@vancleve is this a valid MWE? It demonstrates the issue I think you have using ProgressMeter
n = 100
p = Progress(n)
for i in 1:n
for j in 1:10
next!(p, step=0, showvalues = [(:j, j)])
sleep(1)
end
next!(p)
end |
Building on #196 for reducing unnecessary expense for tight loops.
Implements lazy-smart time checking. Previously
time()
was polled for everynext!
, which is about ~30ns, so can be a bit of a slow down for tight loops.This takes the approach of iteratively predicting the number of iterations for the first print period to be reached, then using that to defer time checking for the next loop for that number of iterations. Then each time the print occurs, the timing is corrected for any overshoot or undershoot. In testing with some debug prints it seems to stabilize quite quickly to check time 1-2 times per
dt
Given locks can be expensive (~140ns on 1.7 currently), this changes to only locking if multiple threads are detected by the next/update functions.
ProgressMeter v1.5.0
This PR