Cache complex list for faster performance
- From: Kevin Walzer <kw@xxxxxxxxxxxxxxx>
- Date: Sat, 28 Jul 2007 23:45:48 -0400
I'm trying to speed up the performance of a GUI application that I develop. Currently the GUI works as a front end to a command-line tool; it fires various commands to the tool, parses the output, and then displays the data in a tablelist widget. My program is slower than I'd like because it's constantly querying the command-line program for everything, including for subsets of larger data sets that it's already returned.
What I want to do is to load the entire data set/list on program startup, then parse that list as needed using my own procedures from within the GUI, so I don't have to fire commands constantly to the external tool. However, I'm not clear on how to do this.
Here's the code that fetches the entire data set:
#show all available ports
proc getAllPorts {} {
global status category portpath verboselevel portlist
clearPorts
set status "Updating package list"
showProgress
set category ""
#get all available ports
set getportlist [split [exec $portpath list] \n]
#get and parse list of installed ports
set portinstalled [split [exec $portpath installed] \n]
set installed [lrange $portinstalled 1 end]
foreach item $installed {
lappend packages [lindex $item 0]
}
#compare installed ports and list of all ports, specify which are installed
foreach item $getportlist {
set program [lindex $item 0]
set version [lindex $item 1]
set searchcategory [lindex [split [lindex $item 2] /] 0]
if { [llength $installed] == 0} {
set myinstalled ""
} else {
set isinstalled [lsearch -all $packages $program]
if {$isinstalled >= 0} {
set myinstalled "Yes"
} else {
set myinstalled ""
}
}
set portlist [list $myinstalled $program $version $searchcategory]
.t.right.upper.frame.listbox insert end $portlist
}
bell
endProgress
set status "Displaying all available ports"
}
The key variable in question here is "portlist." That's the final list that is dumped into the tablelist widget. How can I store/cache the entire contents of $portlist so that I can parse/query it as needed? If it's feasible to do this as a global variable, I haven't figured out how to do it--trying later to find "portlist" only returns the first item of the list. The list has about 4,000 items in it, each line of the list structured as {$myinstalled $program $version $searchcategory}.
Any advice is appreciated.
--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
.
- Follow-Ups:
- Re: Cache complex list for faster performance
- From: Stephan Kuhagen
- Re: Cache complex list for faster performance
- Prev by Date: serial port: fconfigure -handshaking fails
- Next by Date: using configure
- Previous by thread: serial port: fconfigure -handshaking fails
- Next by thread: Re: Cache complex list for faster performance
- Index(es):
Relevant Pages
|