This may be interesting as a general idea for someone who has been wandering why comparing of two list is slow and has not yet have this "aha" moment for some reason.
It's half .NET question/half autocad, so I think it is still a good place to ask.
Lets say you have your list of custom objects, holding length, area and objectid.
Now, user selection has changed, you want to update your list based on user selection and you use impliedselectionchanged event to find all selected items.
You need to remove the ones not currently in selection and add the new ones. Now, I still have not found simple routine to do this, but the observations is - when comparing, numbers are the fastest to compare, but you just forget this. And here are the times it take to compare (on remove!), using "contains" on 20 000 objects on i3 machine.
comparing object itself to other object=
12 secscomparing objectid to objectid =
8 secsif you take just string, and let strings be compared, it all goes faster!:
objectid.tostring =
4 secspeed things up with paralell processing
objectid.tostring (asparalell)=
2 secand if you use
number, it is the fastest you can do
objectid.handle.value (asparalell)=
1 sectest routine that I have used:
Public Shared Sub selectionchanged()
Dim candidates As New List(Of ObjectId)
For Each o As ObjectId In get_selected_oids()
If o.ObjectClass.IsDerivedFrom(RXClass.GetClass(GetType(Curve))) Then
candidates.Add(o)
End If
Next
Dim oidOLD = (From o As LengthAreaObject In lengthAreaList Select o.oid).ToList
Dim oidOLD_NODEL = (From o As LengthAreaObject In lengthAreaList Where o.but_not_this_one= False Select o.oid).ToList
Dim oidstoadd = candidates.Except(oidOLD).ToList
Dim oidstoREM = oidOLD_NODEL.Except(candidates).ToList
Dim oidstoremStr As New List(Of String)
For Each o As ObjectId In oidstoREM
oidstoremStr.Add(o.ToString)
Next
Dim oidstoremNum As New List(Of Long)
For Each o As ObjectId In oidstoREM
oidstoremNum.Add(o.Handle.Value)
Next
Dim rlist As List(Of LengthAreaObject) = (From i As LengthAreaObject In lengthAreaList.AsParallel Where oidstoremNum.Contains(i.oid.Handle.Value)).ToList
lengthAreaList.RemoveRange(rlist)
lengthAreaList.AddRange((From o As ObjectId In oidstoadd Select New LengthAreaObject() With {.oid = o}).ToList)
End Sub
Now, when we know this, then all there is left is to find some clean routine (possibly linq) to actually do this job.
...so if someone has idea?
* I was also wondering if it is possible to fast convert objectid to number, and not to use handle. Just a thought...