Skip to content

Make statusbar faster#286

Open
AlexKurek wants to merge 4 commits into
lofar-astron:masterfrom
AlexKurek:Make-statusbar-faster
Open

Make statusbar faster#286
AlexKurek wants to merge 4 commits into
lofar-astron:masterfrom
AlexKurek:Make-statusbar-faster

Conversation

@AlexKurek
Copy link
Copy Markdown
Contributor

@AlexKurek AlexKurek commented May 30, 2026

This does not require an extensive testing, since I havent touched computations. Just look at ncalls and it explains everything. Now printing and checking the terminal size occurs only 5x / sec.
For a 1.5 GB FITS:
before:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     5823    0.018    0.000   10.835    0.002 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:70(increment)
     5841    0.036    0.000   10.809    0.002 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:46(__print)
     5851    0.023    0.000   10.764    0.002 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:33(__getsize)

after:

     5823    0.007    0.000    0.208    0.000 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:79(increment)
       87    0.001    0.000    0.260    0.003 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:56(__print)
       97    0.001    0.000    0.294    0.003 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/statusbar.py:40(__getsize)

This 3 functions are 52x faster.
The entire run is 2.6% faster.

Copy link
Copy Markdown
Collaborator

@gmloose gmloose left a comment

Choose a reason for hiding this comment

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

I think it's OK to only update every 200 ms. I'm don't completely understand the other changes that I commented on.

Comment thread bdsf/statusbar.py Outdated
if self.max == 0:
sys.stdout.write(self.color + self.text + '[] 0/0\033[0m\n')
else:
# Recalculate comp in case the terminal size (self.columns) has changed
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment doesn't match with the conditional (self.max != 0). So either the comment or the code is incorrect. Also, it's not completely clear for me why you moved this line from the increment() method into the __print() method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We want the progress bar to handle terminal resizing at any moment, so the calculation of self.comp must always happen immediately after checking the terminal size.
If/else is there to prevent division by zero error.

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