Skip to content

Reduce startup time for gambit --help and gambit --version#590

Merged
ChrisJChang merged 3 commits into
masterfrom
improve_startup_time
Jun 22, 2026
Merged

Reduce startup time for gambit --help and gambit --version#590
ChrisJChang merged 3 commits into
masterfrom
improve_startup_time

Conversation

@anderkve

@anderkve anderkve commented May 6, 2026

Copy link
Copy Markdown
Collaborator

This PR uses two shortcuts to reduce the GAMBIT startup time for the trivial GAMBIT invocations gambit --help, gambit --version and simply gambit with no arguments. In all these cases we just want to print some message to the terminal and exit, so there is no need to wait for the full GAMBIT initialisation.

The first shortcut is in core.cpp, where we get in before the check_databases step. On testing this saved ~1 second (~25% of the GAMBIT init time on those tests).

The second shortcut lives in the preload library and is for now Linux-only (it uses /proc/self/cmdline). Here the preload library directly identifies the trivial gambit invocations and outputs the correct terminal output (version number or CLI help text) and exits directly, without ever initialising the main gambit executable. So with this shortcut there is ~no startup time at all. For non-Linux systems, we just continue to the main GAMBIT executable where the first shortcut still saves us a bit of time.

To avoid duplicating the CLI help text in the code, it has been extracted to a header file gambit/Core/cli_help_text.hpp.

anderkve added 3 commits May 5, 2026 20:26
…nary loads.

By letting the gambit_preload library identify trivial gambit invocations like
"gambit --help" and "gambit --version" and produce the correct CLI help text,
we avoid having to wait for the full GAMBIT initialisation for these simple cases.
(The GAMBIT initialisation typically takes a few seconds.)
@anderkve anderkve requested a review from patscott May 6, 2026 14:34
@anderkve anderkve added the Core Core group task label May 6, 2026

@ChrisJChang ChrisJChang left a comment

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.

This appears to work for me, and I can see it being faster.

I noticed that if you run with a flag that is not recognised by the preload (e.g. when I accidentally wrote -help instead of --help), it will do the full initialise before parsing the inputs. Presumably the preload check only checks for specific cases, so this is the correct behaviour.

@ChrisJChang ChrisJChang merged commit b4c3e6d into master Jun 22, 2026
2 of 4 checks passed
@ChrisJChang ChrisJChang deleted the improve_startup_time branch June 22, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Core Core group task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants