Writing Efficient Code in Dyalog

Roger Hui




Abstract

Part I. Performance Tips

A review of performance tips and rules of thumb useful for writing efficient code.

Part II. Special Code

Many primitives contain special code for certain arguments to effect time and/or space savings not available to general arguments; moreover, some phrases are “recognized” and are supported by special code. (These are in addition to idioms.) We explore special codes with emphasis on the newer constructs.
 

Part I. Performance Tips

•  cmpx and wsreq
•  cmpx ⍵     compares expression timings
•  1 1 cmpx ⍵ gets actual times
•  wsreq ⍵    workspace required
•  work on big chunks of data
•   amortize fixed costs over more data
•  keep data together
•   arrays are stored in row-major (ravelled) order
•   cache misses are expensive
•  order of complexity
•   know the order of complexity of primitives
•   avoid O(n*2) operations
•  sorting and searching
•   sorting is faster than grading
•   exploit small range integers
•   x⍳x is useful (and optimized)
•   use ⎕ct←0 if possible
•   beware of O(n*2) cases
•  utilities
•   utilities create centers of gravity
•   dfns are faster than tradfns
•   imitate primitives from other languages

Part II. Special Codes

•  within a primitive
•  datatype
•  boolean data
•  special but common cases
 
•  Idioms
 
•  operators
•  
•  
 
•  trains
•  f¨ ⊂
•  1 ⍳⍨ comp
•  ≢∪

References

[0]   Hui, Roger, Performance Tips, Dyalog ’12, Elsinore, Denmark, 2012-10-14.
[1] Hui, Roger, Exploring Index-Of, Dyalog ’14, Eastbourne, UK, 2014-09-21.
[2] Hui, Roger, A Speed-Up Story, Dyalog Blog post, 2014-11-05.
[3] Hui, Roger, Exploring Key, Dyalog Blog post, 2015-04-13.
[4] Hui, Roger, A Dialog on APL, Dyalog Blog post 2015-05-18.


Presented at Dyalog ’15, 2015-09-10.

created:  2015-05-24 22:25
updated:2015-08-04 19:05