Skip to content

Speedup getTerminalSize#287

Merged
gmloose merged 2 commits into
lofar-astron:masterfrom
AlexKurek:Speedup-getTerminalSize
Jun 1, 2026
Merged

Speedup getTerminalSize#287
gmloose merged 2 commits into
lofar-astron:masterfrom
AlexKurek:Speedup-getTerminalSize

Conversation

@AlexKurek
Copy link
Copy Markdown
Contributor

Python 3.3+ has a build in get_terminal_size in shutil, so this code is not needed.
Similar as #286, it does not require extensive testing, since I havent touched computations.

For a 1.5 GB FITS:
before:
5851 0.096 0.000 16.327 0.003 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/functions.py:1970(getTerminalSize)
after:
5851 0.006 0.000 0.070 0.000 /home/akurek/miniconda3/envs/pybdsf_3_14/lib/python3.14/site-packages/bdsf/functions.py:1971(getTerminalSize)
233x 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.

Nice improvement, but I have a question about the fallback value you're using (see above).

Comment thread bdsf/functions.py Outdated
Comment on lines +1979 to +1980
# We set it to (80, 25) to maintain the identical default values as the old code.
size = get_terminal_size(fallback=(80, 25))
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.

Where did you find those defaults? I don't see them in the original code. In will return (0, 0) if it cannot determine the terminal size. I can live with (80, 25), but also with (80, 24), which is the default if you don't provide a fallback. However, I'm not 100% sure if (0, 0) is treated as special value elsewhere in the code.

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.

(80, 25) is the default terminal size. But I guess I shouldn't have changed that in this PR, since this PR is about speed optimization. For me both (80, 25) and (0, 0) worked, but I have restored (0, 0) in this PR.

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.

Thanks, looks good.

@gmloose gmloose merged commit 3ffd763 into lofar-astron:master Jun 1, 2026
1 check passed
@AlexKurek AlexKurek deleted the Speedup-getTerminalSize branch June 1, 2026 08:22
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