Slow Performance Setting the backColor property of Text
Posted: Sat Oct 19, 2013 3:44 pm
Hi everyone,
First, the questions I hope to have answered:
Why does setting the backColor property take so long?
What can be done speed up the performance?
The background:
I developed a searchable text field that highlights all instances of whatever characters you type into the search box. It works great, BUT, for search entries where there are a lot of occurrences, the performance is painstakingly slow. The process for the "search" can be broken down into two parts:
1. Find the location of all occurrences of the search entry (and store in an array)
2. Highlight all occurrences of the search entry
I assumed it was the first item that wasn't very efficient, but after some timing tests, I realized it was the highlighting process that was slow. Below are some results from the timing tests:
Finding all r's took: 0.001seconds
Highlighting all r's took: 1.877seconds
Number of Characters: 166
Finding all p's took: 0.001seconds
Highlighting all p's took: 0.242seconds
Number of Characters: 36
Finding all l's took: 0.001seconds
Highlighting all l's took: 0.665seconds
Number of Characters: 65
Finding all a's took: 0.002seconds
Highlighting all a's took: 3.35seconds
Number of Characters: 210
The highlighting code that is being used is:
Where this gets really interesting is when the timing tests were done within this routine. The thing that takes multiple seconds has been tracked to the following line of code:
I have an idea for fixing this, but it is not pretty.
Cheers,
Tom
First, the questions I hope to have answered:
Why does setting the backColor property take so long?
What can be done speed up the performance?
The background:
I developed a searchable text field that highlights all instances of whatever characters you type into the search box. It works great, BUT, for search entries where there are a lot of occurrences, the performance is painstakingly slow. The process for the "search" can be broken down into two parts:
1. Find the location of all occurrences of the search entry (and store in an array)
2. Highlight all occurrences of the search entry
I assumed it was the first item that wasn't very efficient, but after some timing tests, I realized it was the highlighting process that was slow. Below are some results from the timing tests:
Finding all r's took: 0.001seconds
Highlighting all r's took: 1.877seconds
Number of Characters: 166
Finding all p's took: 0.001seconds
Highlighting all p's took: 0.242seconds
Number of Characters: 36
Finding all l's took: 0.001seconds
Highlighting all l's took: 0.665seconds
Number of Characters: 65
Finding all a's took: 0.002seconds
Highlighting all a's took: 3.35seconds
Number of Characters: 210
The highlighting code that is being used is:
Code: Select all
on doInitialHighlite
--do the highlighting here...
set the backColor of char 1 to (number of chars in field "searchField") of field "searchField" to empty
set the backColor of field "searchField" to "#CCCCCC"
set the locktext of field "searchField" to true
get the keys of theResultsArray
repeat for each line tLine in it
put theResultsArray[tLine]["First Char"] into theFirstChar
put theResultsArray[tLine]["Last Char"] into theLastChar
if tLine = 1 then
put 1 into theIndex
set the hiliteColor of field "searchField" to "yellow"
-- select the char theFirstChar to theLastChar of field "searchField"
set the backColor of char theFirstChar to theLastChar of field "searchField" to "yellow"
else
set the backColor of char theFirstChar to theLastChar of field "searchField" to "#FFFFFF"
end if
end repeat
end doInitialHighlite
Code: Select all
set the backColor of char theFirstChar to theLastChar of field "searchField" to "#FFFFFF"
Cheers,
Tom