![]() Xojo is great for building structured code using methods, but we can speed things up in a loop by reducing the number of calls to methods. In our tiny example above, the CalculateTotals method gets called 5,000 times. If the code within the CalculateTotals method were put directly into our loop instead, 5,000 calls to the method would be eliminated, so the loop code would run faster. This is inefficient and can be improved by adding the entire row to the list in one go: MyListbox.Cell(MyListbox.LastIndex,3) = z MyListbox.Cell(MyListbox.LastIndex,2) = y MyListbox.Cell(MyListbox.LastIndex,1) = x MyListbox.Cell(MyListbox.LastIndex,0) = w I often see code like this to add rows to Listboxes: MyListbox.AddRow " " If you have a feature that processes a large volume of data, and various different methods get called from inside a loop, flattening the code would help improve performance. This works significantly faster and is less code to write. ![]() If your lists are long and have several columns you will see a difference. …you can store values in variables first: And if you don’t want long and hard to read lines of code like this… MyListbox.AddRow rs.Field(âvalue1â).StringValue, _ For a WebListbox on a WebPage it is a very noticeable difference. Loops are used to repeat blocks of code over and over again. Take the following example, which may look familiar: If we can reduce inefficiencies in loop code, we can make significant performance improvements. This makes the code easier to read and edit. Although it is not as fast as the single line of code to add the row, it is still much faster than adding a blank row and then populating each cell one by one.Īnother tip is to make a Listbox invisible while rows are being added, and visible again when it is ready. This is not necessary for most uses, but if you are populating a Listbox with a very large amount of data, this can bring a big performance improvement. To make sure there isn’t a blank space in the UI while it is invisible, an identical blank Listbox can be put behind the Listbox in use, or a “please wait” image can be used instead, but you have to remember that the window may be resizable and the list may be resized too.Īnd don’t forget to use the Xojo Profiler to check your code performance when you see it needs some work. ![]() First work on the functions that take the longest, and then look at commonly used methods to see if you can speed them up using these tips.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |