The simplest optimization of shortest_first is to use a hasharray to cache the results of the length calculation: sls[a]:=slength(string(a))$ shortest_first(s):= sort(args(s),lambda([a,b],sls[a]<sls[b]))$ translate(shortest_first)$ This improves the time from 45 seconds to 6. -s