Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Lightning-fast VARS command

14 views
Skip to first unread message

John H Meyers

unread,
Nov 15, 1997, 3:00:00 AM11/15/97
to

VARS (list variables in current directory) has been nominated for
the all-time most leisurely-paced command in the HP48, easily
out-classing even the slowest of the application form interfaces,
except, of course, for the Variable Browser, which -- you guessed
it -- depends completely upon DOVARS (the internal VARS).

Here are my timings for VARS for two different HOME directories:

98 variables: 6.6 seconds

191 variables: 28.2 seconds

As this suggests, the length of time it takes to execute VARS
is roughly proportional to the *square* of the number of
variables -- a very poor showing for a function which should
be roughly linear -- which is due to the fact that the internal
DOVARS function uses yet another internal function DODIRPRG,
which in turn appends each individual result (a variable name)
to a cumulative list, which gets longer and longer, slower
and slower, instead of simply putting each result one at a time on
the stack, counting them, and making one final list at the very end.

I suppose no one knows why HP neglected to use this "meta-object"
approach, which is extremely common throughout the system internals,
to speed up such an important command; perhaps there is an iron-clad
rule that no one can change a piece of coding, one it has been used
for some time, unless it has a serious bug -- timing not counting
as a "bug" -- but wasn't it known after two years experience
with the HP48S/SX that this was a problem?

It appears likely that the utterly unacceptable performance
of the G/GX Variable Browser when used in large directories
is due to a dependence on this same internal function, which
appears to have to be executed once for each individual
variable name displayed (thus it takes half a minute
*per*variable* to list items in my G/GX HOME directory).

Outside of commands contained in large libraries, the
only fast replacement for VARS which I have come across
is DIRVARS on Goodies Disk #8, yet DIRVARS does not
truly replace VARS, because although it can list any
"hidden" variables, which might be useful, it also lists any
null-named variables, such as the Hidden Directory in HOME,
which is not compatible with VARS; DIRVARS is also about 286 bytes,
and contains some ML code (why?).

Well, I wanted a fast VARS replacement that I can keep in my HOME
directory in my 32K HP48G, so I began writing one myself in SysRPL
(the very thing I usually steadfastly avoid, since, like Euclid, I
try to construct everything using only straight and narrow User-RPL :)

When I was done, I compared my efforts vs. VARS and VARS2
from HACK version 6.8 (from GD#10), in which, oddly enough,
VARS is much longer and contains ML code, like DIRVARS,
while VARS2 (which functions exactly like DIRVARS)
is very much shorter and contains no code.

VARS2 beat me by a whole 2.5 bytes, although the method is
essentially the same, so I scrapped my own version and have adopted
the code in VARS2. To change VARS2 into a very satisfactory
replacement for VARS, it is only necessary to change the names
of two function calls, as listed below; thus both programs
are the same 42.5 bytes in length.

Now let's check those timings again:

Built-in VARS FASTV FASTA (see below)
------------- ----- -----

98 variables: 6.6 seconds .328 .281

191 variables: 28.2 seconds .661 .567

The relationship is now approximately linear in the number
of variables, as we expected, and for 191 variables it is
about 50 times as fast as the built-in VARS!

Here is a program to create the non-editable FASTV and FASTA
(the latter lists "all" variables, including null-named and hidden):

%%HP: T(3); @ Requires ASC\-> from the FAQ or Goodies Disk #1
\<<
"D9D2051A81A5D8012681DA9169E550A3E262A170881303E280CAF0634815A368
12FA308C17095450B21305343" ASC\-> 'FASTV' STO
"D9D2051A81A5D8062380DA9169E550A3E262A170881303E280CAF06348156738
02FA308C17095450B213093AD" ASC\-> 'FASTA' STO
'FASTV' RCL "VARS" #5B15h SYSEVAL STO @ See explanation below
\>>

Note that you have to install ASC\-> before running this program; you
can purge ASC\-> afterwards if you don't have any further use for it.

If you wish, you can compile your User-RPL programs so that VARS
will automatically be replaced by a reference to this new program,
much as happens when you install the HACK library, after which
references to the word VARS in newly compiled User-RPL programs
are automatically compiled to reference Hack's replacement command.

To help you do this, I included in the above program a function
to copy FASTV into a variable named VARS (in whatever directory
is current when you run the above program); if you don't want
this extra copy named VARS, you can just purge it: 'VARS' PURGE

You will notice that once a variable named VARS exists, the
quoted name 'VARS' can be compiled without a syntax error,
because the command line compiler, when searching for
a meaning for every word in the command line, finds the
variable named VARS even before it searches any built-in
ROM libraries, causing the word VARS to be compiled
as a variable name, rather than as a built-in command;
if you keep this variable in HOME then it will always be
"visible" to the compiler when you enter or edit programs.

Please take note of the following:

o User-RPL programs which were compiled before you installed VARS
will not start using the new program until you re-compile them,
which means that you begin editing the program as if to change it,
but then all you do is press ENTER without making changes.

o The sizes and checksums of User-RPL programs will change when
compiled to use the variable VARS, because of the change in type
and size of the object created by the word VARS.

If you purge the variable named 'VARS', then programs compiled to
use it will no longer work; however, if you re-compile any such
program once again afterwards, each word VARS will once again
be replaced by the original built-in command.

o Pressing the VARS menu key in the MEMORY DIR command menu
continues to directly execute the built-in (slow) VARS,
because the command menu is already "pre-compiled"
in ROM within the calculator.

However, if you press right-shift ENTRY before pressing the VARS
command key, the word VARS simply appears in the command line;
when you press ENTER to compile the command line, then the
faster VARS will be executed.

o SysRPL/ML programs will not take advantage of the faster VARS,
because internal DOVARS calls can not so readily be replaced
with references to the new user variable.

o User-RPL programs received by your calculator using Kermit's
ascii mode are compiled upon receipt, and hence will use the
new VARS if present; programs received in binary mode are
stored exactly as they existed on the system from which you
received them, which may not have had this version of VARS.

o The Variable Browser application is also pre-compiled in ROM,
and unfortunately can not be fixed to use this faster VARS.


Here's a program which only the new VARS makes even feasible,
time-wise, if you have a large HOME directory which in turn
has many sub-directories:

%%HP: T(3); @ Store into 'UP' or 'UPD' in HOME
\<< PATH DUP SIZE GET UPDIR VARS SWAP POS 6 / CEIL 1 % 2 + MENU \>>

This program (just like Joe Horn's UPD from GD#10/Utils)
replaces UPDIR (you may assign it to that key);
whenever you go up to a higher directory from a lower one,
it displays the VAR menu for the higher directory in such
a way that the (up to) six menu labels displayed always include
the tabbed label for the lower directory you just came from, so
that you don't need to press NXT... to get back to where you were.


Here's the SysRPL program for FASTV/FASTA:

FASTV ( FASTA ) - by whoever supplied VARS2 in HACK.LIB
---------------

::
CK0NOLASTWD
CONTEXT@
LastNonNull ( LASTRAM-WORD )
NOTcase
NULL{}
ZEROSWAP
BEGIN
DUP
RAM-WORDNAME
UNROT
SWAP#1+SWAP
PrevNonNull ( PREVRAM-WORD )
NOT UNTIL
{}N
;

The reason that FASTV is slightly slower than FASTA is the
extra bit of checking done by the "...NonNull" words to
stop at the first null-named variable encountered, if any.

So why are most of the other VARS replacement programs
(except for VARS2 in Hack lib) so big? Are they so much
faster than this tiny one?

I hope that this helps speed things up for folks who don't
have room for the big toolkit libraries, but still want
a little fast action around here :)

-----------------------------------------------------------
With best wishes from: John H Meyers <jhme...@mum.edu>

Balazs Fischer

unread,
Nov 17, 1997, 3:00:00 AM11/17/97
to John H Meyers

---===> Quoting John H Meyers <===---


JHM> VARS (list variables in current directory) has been nominated for
JHM> the all-time most leisurely-paced command in the HP48, easily
JHM> out-classing even the slowest of the application form interfaces,

No, the libs command is even slower :-).

cu

Balazs Fischer

Balazs....@studbox.uni-stuttgart.de
PGP Key: http://pgp5.ai.mit.edu:11371/pks/lookup?op=get&search=0xED7447E5

... My modem has voice recognition. Whenever i say Hang Up质\茊噲 NO CARRIER

0 new messages