Hello The function contains arrdup() that includes elements beyond end index. I've replaced it with arrdup_max() that has limit parameter – will duplicate at most that limit of elements. Following test code: test_fun() { local -a arr repeat 12; do arr+=( "abcdefghijklmnop" $arr ) done local -a arr2 repeat 2000; do arr2=( ${arr[1,300]} ) done } generates array of 4095 elements, and the running times are 1099 ms (optimized) vs 2038 ms (unoptimized). The array generation utilizes previous array optimization. More, I suspect a memory leak in following code that has been replaced: if (v->end <= v->start) s[0] = NULL; else if (arrlen_ge(s, v->end - v->start)) s[v->end - v->start] = NULL; That code adapts array according to end index – however it seems that strings after the NULL are then unreachable to freearray() ? That said, I wasn't able to obtain the memory leak with repeated ${arr[1,2]} use for $#arr > 2. Interesting that some tests fail (e.g. ./Y03arguments.ztst) if I here duplicate nular instead of doing: } else if (v->end <= v->start) { s = arrdup_max(s, 1); s[0] = NULL; like in the original code. The test output is then: @@ -6,6 +6,6 @@ line: {tst r}{} line: {tst x}{} line: {tst x }{} -MESSAGE:{no more arguments} +MESSAGE:{} line: {tst x y }{} -MESSAGE:{no more arguments} +MESSAGE:{} -- Sebastian Gniazdowski psprint@fastmail.com