Skip to content

Conversation

orlitzky
Copy link
Contributor

Reimplement the _commands() method that queries maxima for a list of valid commands. Gives about a 9x speedup here, and should eliminate one of the CI "slow doctest" warnings.

The maxima _commands() method was implemented in terms of the
tab-completion method, completions(), which goes one-letter-at-a-time
and is very slow as a result. We reimplement it directly to call
maxima's apropos() with the empty string. This gets all commands in
one shot. We also clean up the list of commands a little by excluding
some junk results. The diff (eliminated elements) from the old list to
the new one is,

  {'SPLITS\\IN\\Q',
   'erf_%iargs',
   'exp-form',
   'is-boole-eval',
   'is-boole-verify',
   'maybe-boole-eval',
   'maybe-boole-verify',
   'sstatus-aux',
   'time\\/\\/call',
   'unknown\\?',
   'zeta%pi'}

The faster method should help avoid warnings in the CI about the test
being too slow.
This parameter was recently made obsolete, and as this is an internal
method, we can just delete it.
@orlitzky orlitzky force-pushed the faster-maxima-commands branch from 3229b57 to 12a2173 Compare August 31, 2025 03:08
Copy link

github-actions bot commented Aug 31, 2025

Documentation preview for this PR (built with commit 5e808ca; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

It probably doesn't matter, but we should prefer the maxima library
interface anywhere that performance might be an issue. We now test
the _commands() method with maxima_calculus (a library interface)
rather than "maxima" (a pexpect interface).
If we use a "\" instead of "-" in the list of bad characters, we catch
all of the existing bad names, but get things like "SPLITS\\ IN\\ Q"
as well.
The _commands() method checks the first character of each command to
make sure that it starts with a letter. This _was_ searching a tuple
(containing 'a' to 'Z'), but it seems to be much faster if we
concatenate them all into one string and search that instead.
@orlitzky
Copy link
Contributor Author

I added a few more small improvements, mainly to eliminate two junk names that snuck in, and to speed up the first-character check.

The switch from maxima to maxima_calculus in the test is actually not an improvement if maxima is bare bones because we load some extra packages in the ECL interface that cause extra names to be defined. But I still think that long-term, it's better to use the library interface (it's more predictable, and we should always be working towards eliminating the pexpect interface entirely).

Using python's walrus operator we can simplify the list comprehension
that builds the list of maxima _commands(). Essentially this allows
us to save the result of foo.strip() and work with that rather than
the original unstripped string foo.
Copy link
Contributor

@fchapoton fchapoton left a comment

Choose a reason for hiding this comment

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

good, thanks

@orlitzky
Copy link
Contributor Author

orlitzky commented Sep 1, 2025

cool, thank you!

vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 4, 2025
sagemathgh-40737: Speed up the maxima _commands() list
    
Reimplement the `_commands()` method that queries maxima for a list of
valid commands. Gives about a 9x speedup here, and should eliminate one
of the CI "slow doctest" warnings.
    
URL: sagemath#40737
Reported by: Michael Orlitzky
Reviewer(s): Frédéric Chapoton, Michael Orlitzky
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants