Blog Post
You might have noticed the other sequence utility methods (unique, remove, removeAll); each was added when we noticed common patterns that were slowing down customizations.
Yap, the first two were actually because of me =D...I had to do exactly the type of N-tree-creating loops to achieve stuff like "unique", your team likely got notice of it because they saw heavy load on the system, then first an improved/refactored/optimized method was suggested, but probably didn't do enough, that's when the custom context object for sequence utils (probably simply a Java class or method call?) was introduced, same for "remove" =)... so yeah, sometimes the FreeMarker code can be optimized (good example with "splice" btw., but we abuse it anyways when doing that kind of logic with it... unfortunately we do not have much of a choice at the moment =), only way of dealing with data on the "backend" with Lithium for us...
regarding
so in a sandbox you can experiment with test data and measure using ".now?long", placed into an or console.log (with ?js_string)
yeah, I'm doing something similar, although I'm using datesupport.now.millisecondsAsString?number, but .now?long looks more efficient tough (can you confirm that? I'll might need to cut off the last 3 digits to get the milliseconds...which would be another operation on it), didn't know I can use ?long with a datetime...but yes, indeed you can, well hidden in the docs =):
The long built-in can also be used with date, time and date-time values to get the value as java.util.Date.getTime() would return. This is useful if you have to call a Java methods that expect a timestamp as a long.
but it's good to know that there are no other performance measuring tools/methods/approaches that I have overlooked =)...
EDIT: played around a bit with your slice() function (tried to do that once as well, but without much success =D), found a variety of issues, please have a look at the examples, which of course you can try here (just paste below code):
<#function splice items start = 0 delete = 0 insert = []> <#if insert?has_content> <#return items[0..!start] + insert + items[(start+delete)..]> <#elseif (delete > 0)> <#return items[0..!start] + items[(start+delete)..]> <#else> <#return items> </#if> </#function> <#assign seq = [1,2,3,4,5,6] /> <#-- expected: [1,2,3,4,5,6,7,8]; result: [1,2,3,4,5,7,8,6] PROBLEM --> <#assign ins = splice(seq,5,0,[7,8]) />
<#-- expected: [1,2,3,4,5]; result: [1,2,3,4,5] OK--> <#assign del = splice(seq,5,1) />
<#-- expected: [1,2,3,4,5]; result: [1,1,2,3,4,5,6] PROBLEM --> <#assign del = splice(seq,-1,1) />
<#-- expected: [1,2,3,4,5]; result: out of bounds exception PROBLEM --> <#--<#assign del = splice(seq,5,2) /> <#list del as s> ${s} </#list>