StyledText speedy on Mac but slow on Windows. Expected?

I have a TextArea which displays large chunks of text from a db table and use various StyledText formatting in it to bold, underline, and bold-underline various parts. Flipping through some of the rows to display the next article from the table is showing different timing results between Mac and Windows. Mac seems flawless and picks up the styled text changes immediately. When testing on Windows, it appears to go through “phases” and takes maybe 2 seconds to fully display the changes. Is this the expected behavior? FWIW, my Mac is newer (about 2 years old) and hefty. Windows is win 10 and several years old (7+ years), so not sure if the user would experience this also on a newer Windows or an older Mac

Here’s what the code looks like. I’m sure there can be improvements since there are a couple of loops and maybe that’s the problem

'get text from db.  topic title at top and centered
dim sql as String = "SELECT * FROM RDguide WHERE ID = '" + TopicIDs(TopIDArrayNum) + "'"
dim rs as RowSet = dbTests.SelectSQL(sql)

txtStyle.StyledText.Text = rs.Column("Topic").StringValue + EndOfLine + EndOfLine + rs.Column("Solution").StringValue

'set up styles
dim startPos, textLength as Integer
txtStyle.StyledText.FontName(0, txtStyle.Text.Length) = "Arial"

'title
txtStyle.StyledText.ParagraphTextAlignment(0) = TextAlignments.Center
startPos = txtStyle.StyledText.Paragraph(0).StartPosition
textLength = txtStyle.StyledText.Paragraph(0).Length

txtStyle.StyledText.Bold(startPos, textLength) = True
txtStyle.StyledText.Size(startPos, textLength) = 24

'main body
txtStyle.StyledText.Size(startPos + textLength, txtStyle.Text.Length - textLength) = 18

'find any headings to bold underline (ends with colon)
dim headingsUB() as String
headingsUB = rs.Column("HBoldUnderline").StringValue.Split("; ")

for i as Integer = 0 to headingsUB.LastIndex
  dim position as Integer
  
  position = txtStyle.Text.IndexOf(0, headingsUB(i))
  
  if position >= 0 then
    txtStyle.StyledText.Underline(position, headingsUB(i).Length) = true
    txtStyle.StyledText.Bold(position, headingsUB(i).Length) = true
  end if
next

'find any headings to underline (terms)
dim headingsU() as String
headingsU = rs.Column("HUnderline").StringValue.Split("; ")

for j as Integer = 0 to headingsU.LastIndex
  dim position as Integer
  
  position = txtStyle.Text.IndexOf(0, headingsU(j))
  
  if position >= 9 then
    txtStyle.StyledText.Underline(position, headingsU(j).Length) = true
  end if
next

Have you benchmarked the subsections of the routine to highlight any glaring failure points?

Its quite possible that the control is redrawing every time you update a property.

There are some Windows declares that might help speed things up. You call a Win32 function to disable drawing, perform your updates and then re-enable drawing (at this point you might have to invalidate your GUI control).

Check out the Freeze Drawing section on this Xojo documentation page:
http://documentation.xojo.com/topics/user_interface/windows_ui_guidelines.html

There is an alternative way using the LockWindowUpdate API function. If you search the forums for LockWindowUpdate you should find postings where people have used it to solve various problems.

1 Like