Choice creation is slow?

Paul Johnston recently asked a similar question about 30 choice controls
with ~1000 entries per control taking around 17 seconds to create. He
was also using Windows XP (in my experience, the slow creation time does
not tend to occur on Windows 2k).

Robin Dunn offered a solution which seems to have solved Paul's problem:
    1. ch = wx.Choice(parent, -1, choices=)
    2. ch.Freeze()
    3. ch.AppendItems(choices)
    4. ch.Thaw()

Or changing your snippet...

        choices=["1 second", "5 secs", "10 secs", "15 secs", "20 secs"]
        ctrlList =
        prevTime = time.time()
        for loopidx in xrange(100):
            wx.Choice(self, -1, choices=choices)
            choices[-1].Freeze()
            choices[-1].AppendItems(choices)
            choices[-1].Thaw()
        print time.time() - prevTime

In running your original snippet on my machine, it took 0.234 seconds.
Running the changed version above runs in .188 seconds. If instead of
adding 5 items to 100 controls, you were adding 100 items 1000 controls,
your original snippet ran 11.44 seconds on my machine, but with the
.Freeze () and .Thaw(), it ran in 6.35 seconds. You may get more
significant improvements than I have been getting, if only because win2k
seems to run faster without .Freeze() and .Thaw() than XP.

Try .Freeze() and .Thaw() as Robin suggests and get back to us.

- Josiah

···

"Lee Merrill" <justducky@nc.rr.com> wrote:

Hi everyone,

    I have a screen that has lots of widgets on it, and the Choice
widgets are taking much longer to create than the other widgets:

        choices=["1 second", "5 secs", "10 secs", "15 secs", "20 secs"]
        ctrlList =
        prevTime = time.time()
        for loopidx in xrange(100):
            ctrlList.append(wx.Choice(parent, -1, choices=choices))
        print time.time() - prevTime

Now with 1 string (e.g. ["1 second"]) this takes .2 seconds, with 3
strings, .34 secs, with 5 strings, .47 seconds. So you can imagine what
the startup time is for hundreds of Choice widgets! Now I was hoping
for fast performance from wxPython, the other widgets are about three times
faster, but that's still not fast!

But the Choice widgets are my main problem, I have lots of them, with
lots of strings, and this is kind of a roadblock at this point.

Any thoughts appreciated,
Lee

P.S. This is with wxPython 2.6.3 and Python 2.4.2 on Windows XP...

Thanks for the reply, Robin, the difficulty I have is that I would like to make a screen with (say) 20 intervals (I really wanted more), and have the same choices be available for each interval. So that adds up! And 10 seconds (and it takes about 30 seconds for the screen to close) may be asking a bit much of the poor user. I'm rather surprised that a hundred or so of such controls can send a 2 Ghz Pentium gasping and wheezing to the showers, indeed, it's the CPU red-lining though, when I start this up. Maybe a profiler would help? Though I'm sure you all have done this. And the other controls are not far behind the Choice/Combobox, at about a third the rate of creating them.

Regards,
Lee

···

----- Original Message ----- From: "Robin Dunn" <robin@alldunn.com>
To: <wxPython-users@lists.wxwidgets.org>
Sent: Wednesday, April 05, 2006 5:37 PM
Subject: Re: [wxPython-users] Choice creation is slow?

And maybe this bug (assuming a bug it be) was not present in a prior release? That would be helpful to know...

I think that speed of appending lots of items in a wx.Choice or wx.ComboBox has always been an issue. That's one of the reasons why most people will tell you not to use it for more than a few dozen items. The other reason is that it is not an easy control for the users to have to select from more than a few items.

Hi Josiah,
    Thanks for your reply, yes, I could only create each line as needed, except when the user loads a saved setup, then I would need to create dozens of lines, each with all their controls, all at one time. As far as notebook pages, I was going to reuse the controls, actually, on every page, and only have one set of controls. I guess I could turn the controls into bitmaps! And then when the mouse hovers over a Choice, quick turn it back into a real Choice control. But this would be a major endeavor (understatement alert!), and this is just my little home project...

Regards,
Lee

···

Are you going to be seeing the controls all on the screen at the same
time? If not, you can dynamically create your choice controls whenever
they would be seen, destroying them when they are hidden. You may be
creating/destroying many of them over the lifetime of the program's
runtime, but the delay for each individual creation/destruction could be
small enough for it to not be noticable.

In terms of destruction, if you want to delay it (so that say switching
notebook tabs, where
these same options are seen), you can always save a timestamp when you
switch away from a control, use a timer to check when a page was last
accessed, and delete the control if it hasn't been accessed in the last
X seconds.

Hello!

Hi Josiah,

> So...what are you writing that needs so many wx.Choice controls?

I am writing a text animation system, see here for the html setup pages that
I am wanting to convert to a wxPython program:

http://leenotes.org/cgi-bin/ta_setup003.py

So I want to allow the user to have up to about 20 intervals for each
animation (though the simple ones would have only three), and I really would
like more even than 20 for the maximum number of intervals, since inserting
a .1 length interval allows for abrupt transitions. And each interval can
have lots of options, and though many of these will turn into sliders (size,
blur, etc.), some of them may need to stay choices: position, for instance
(though I could make this a button that brings up a dialog, come to think of
it).

However, in any case, I have so many controls that it doesn't matter so very
much that Choice takes a long time to create, all the other controls each
take about a third as long as a Choice, so I'm kind of up against the
creation time, regardless.

I appreciate the input!

To me, this sounds like something similar to a non-linear video
editing program - it has different "scenes" connected by
"transitions". One way to implement that would be a "time line" window
that gives a view of the complete work (or part of it if it doesn't
fit the screen, scrollable) and two dialogs to control the transitions
and images (with "previous" and "next" buttons, perhaps). Clicking on
one "frame" of the "time line" would enable control for the image,
clicking on the line between two frames would enable control for the
transition.

Disclaimer: It might be a good idea, it might be useless - YMMV.

regards,
Harald Stürzebecher

···

2006/4/9, Lee Merrill <webbily1@nc.rr.com>:

That's a good idea, thanks, and maybe I could do three of them (since the simplest version will have three intervals), and then pop in two next/previous buttons...

Lee

One way to implement that would be a "time line" window

that gives a view of the complete work (or part of it if it doesn't
fit the screen, scrollable) and two dialogs to control the transitions
and images (with "previous" and "next" buttons, perhaps). Clicking on
one "frame" of the "time line" would enable control for the image,
clicking on the line between two frames would enable control for the
transition.

Disclaimer: It might be a good idea, it might be useless - YMMV.

regards,
Harald Stürzebecher