Hey DenisT, I tried a few different methods to optimize the script further based on your advise, and was able to get it down to about 37ms (from 49ms) using this approach:
(
objMod = modpanel.getCurrentObject()
allSelEdgesBIT = objMod.getSelection #Edge
allSelEdges = allSelEdgesBIT as array
gev = modFullName.GetEdgeVertex
gvec = modFullName.GetVertexEdgeCount
gve = modFullName.GetVertexEdge
gc()
t1 = timeStamp()
allEdjVrts = #{} ; for edj in allSelEdges do ( join allEdjVrts #{(gev edj 1), (gev edj 2)} )
combinedEnds = #() --Each sub-array looks like this: #(endVertIndex, endEdgeIndex)
checkedVrts = #()
for vrt in allEdjVrts do (
if (finditem checkedVrts vrt == 0) do (
vrtEdjs = (for i=1 to (gvec vrt) collect (gve vrt i)) as bitarray
selEdjs = vrtEdjs * allSelEdgesBIT
if selEdjs.numberSet == 1 do (
selEdj = (selEdjs as array)[1]
selEdjVrts = #{(gev selEdj 1), (gev selEdj 2)}
remainingVrt = ((selEdjVrts - #{vrt}) as array)[1]
append combinedEnds #(vrt, selEdj)
append checkedVrts remainingVrt
)
)
)
format "maxscript\nresult:%\ntime:% ms\n" test (timeStamp() - t1)
)
I don’t think I’ll be able to optimize it any further, but thankfully this is already easily fast enough for the purposes I intend to use it for. Thanks again guys for the help 