Length of variable names and execution speed

General APL language issues

Length of variable names and execution speed

Postby augustk on Tue Aug 18, 2020 3:01 pm

I have a very vague idea of what Dyalog APL does when a function is fixed (established) in the workspace. I imagine that it is translated into an internal representation which can be efficiently interpreted. More specifically, are variable names kept intact or are they translated to something shorter for efficient retrieval; in other words can the length of variable names affect the execution speed?

On a side note I lost my first post after my login timed out and I pressed Submit. Not very nice.
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am

Re: Length of variable names and execution speed

Postby Veli-Matti on Wed Aug 19, 2020 9:58 am

Hi,
as far as I know, the variable lengths are no big deal. If I remember it right, the Dyalog guys talk something about using internal tokens here..
For example, let's create following variables with diferent name lengths(in v.18):

      a←1e6(?⍴)0 ⋄ b←1e6(?⍴)0
⍎(1e3/'a'),'←a' ⋄ ⍎(1e3/'b'),'←b'
⍎(1e6/'a'),'←a' ⋄ ⍎(1e6/'b'),'←b'
(a+b)≡⍎(1e6/'a'),'+',1e6/'b'
1

...and make three stup..simple functions:
      ⎕fx'z←foo' 'z←a+b'
⎕fx'z←goo' ('z←',(1e3/'a'),'+',1e3/'b')
⎕fx'z←hoo' ('z←',(1e6/'a'),'+',1e6/'b')

Speed testing them against each other gives no visible difference
      ]runtime -c "foo" "goo" "hoo"

foo → 2.2E¯3 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
goo → 2.2E¯3 | -1% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
hoo → 2.3E¯3 | 0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕

Of course, executing takes a tad longer:
      ]runtime -c "⍎'a+b'" "⍎(1e6/'a'),'+',1e6/'b'"

⍎'a+b' → 2.2E¯3 | 0% ⎕⎕⎕⎕⎕⎕
⍎(1e6/'a'),'+',1e6/'b' → 1.5E¯2 | +591% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕


But I assume that in normal cases the variable name lengths do not matter.
-Veli-Matti
Veli-Matti
 
Posts: 93
Joined: Sat Nov 28, 2009 3:12 pm

Re: Length of variable names and execution speed

Postby Vince|Dyalog on Thu Aug 20, 2020 8:37 am

Hi AugustK,

When the function is fixed, the APL source is turned into numerical tokens. The names will be indices into a symbol table. The length of the names will not cause a problem or slow performance unless you are using execute like Veli-Matti pointed out.

Regards,

Vince
Vince|Dyalog
 
Posts: 412
Joined: Wed Oct 01, 2008 9:39 am

Re: Length of variable names and execution speed

Postby augustk on Thu Aug 20, 2020 10:22 am

Thanks for the clarification, Vince.
augustk
 
Posts: 27
Joined: Tue Feb 05, 2019 11:54 am

Re: Length of variable names and execution speed

Postby AndyS|Dyalog on Thu Aug 20, 2020 10:56 am

Several years ago we found a number of bugs due to exceedingly long names, so we prevented a number of those bugs by simply limiting the length of a name to something like ¯1+2*31. Mind you, once you get to 2*10 or so I think you'll find that you'll hit problems with ⎕NR etc.

Once you've got your function compiled, then as Veli-Matti and Vince state, the length of a name won't impact the performance of the function. But the longer a name, the longer it will take to open the editor, or generate the output of )si etc etc. And the autocomplete dropdown might take some time to open !

And of course the name has to be held in the workspace .. so the longer the names, the less space there is for other stuff.
User avatar
AndyS|Dyalog
 
Posts: 257
Joined: Tue May 12, 2009 6:06 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest