Class in RowTag

Is there any way to speed up retrieving a RowTag as Variant from a listbox? For instance, each row I have a series of special properties in a class I assign to RowTag:

SidebarListboxData.Picture = Whatever
SidebarListboxData.IsHeader = True
SidebarListboxData.ShowCountBox = True

But it’s super slow accessing this custom RowTag class of SidebarListboxData when converting it from a variant to a SidebarListboxData. At least, i think that’s where the bottleneck is.

I don’t get it. You mean you are serializing a class and storing it?

No, just assigning the class to RowTag

Have you run the code profiler to check?

Yes, oddly this one is quite slow:

Public Function RowInBounds(row As Integer) As Boolean
If row > me.RowCount-1 Then Return False
If row < 0 Then Return False
Return True
End Function

And so is this:
Public Function ActualRowIsEntireListHeaderKSW(Index As Integer) As Boolean
If me.RowCount > 0 and me.PrivateRowData(0).RowIsEntireListHeader and _
(index = me.ScrollPosition) Then
index = 0
End If

If Not me.RowInBounds(index) Then Return False
Return me.PrivateRowData(Index).RowIsEntireListHeader
End Function

Where privateRowData is this:

Private Function PrivateRowData(row_num As Integer) As SidebarListboxData
Var xData As SidebarListboxData = SidebarListboxData(Super.RowTagAt(row_num))

If xData = Nil Then
xData = New SidebarListboxData(False,Nil,kRowTypeNormal,Nil,False)
Super.RowTagAt(row_num) = xData
End If

Return xData
End Function

So your workflow is like:

Var c As New MyClass() = 111
c.bbb = 222

MyListBox.RowTagAt(row) = c  // store

// Then reuse somewhere as

Var c As MyClass = MyListBox.RowTagAt(row)

MessageBox + " " + c.bbb.ToString

And you find that box/unbox is too slow?


Before we go down this path, what’s “quite slow”? Are we talking seconds or milliseconds?

A couple minutes for a listbox with thousands of rows.

I guess you are doing a lot of checks using nested methods that maybe can be avoided using more direct approaches

The profiler will show you the total time, the number of calls and then the time per call.

The reason I’m asking is that what assigning a variant to a property of a particular type should take a minimal amount of time… like less than a millisecond.

But I notice that your routine creates a few instance if one hasn’t been assigned yet. Could it be that’s where the time actually is?

i think this is unnecessary “SidebarListboxData(Super.RowTagAt(row_num))”

should be just assign the object what it is inside
Var xData As SidebarListboxData = Super.RowTagAt(row_num)

1 Like

Just trying to find ways to potentially improve performance.

Why are you using Super.RowTagAt? Shouldn’t that just be me.RowTagAt?

Nope because I’m replacing the function with one of the same name

Might that be part of the slowdown? In general, you seem to be adding a lot of additional function calls, which can be slow.

String.IndexOf() is 500x slower than Dictionary.HasKey… 3.3 seconds for the below code versus 0.006

Var dStart, dEnd As Double
Var i, iEnd As Integer
Var dDict As New Dictionary

Var sCheck() As String
For i = 1 to 10000
Var the_value As String = "Untitled Copy " + Str(i+1)
sCheck.Append the_value
dDict.Value(the_value) = True

Var sFinal() As String
dStart = System.Microseconds
iEnd = sCheck.Count-1
For i = 0 to iEnd
If sCheck.IndexOf(sCheck(i)) = -1 Then Break
dEnd = System.Microseconds

MsgBox Str((dEnd-dStart)/1000000) + " seconds"

dStart = System.Microseconds
iEnd = sCheck.Count-1
For i = 0 to iEnd
If Not dDict.HasKey(sCheck(i)) Then Break
dEnd = System.Microseconds

MsgBox Str((dEnd-dStart)/1000000) + " seconds"

Please, insert code into code blocks (select and Control+E)

// or click here