[wxPython-users] number of objects drawn to dc
Chris Mellon
arkanes at gmail.com
Mon Oct 1 14:48:34 PDT 2007
On 10/1/07, Chris Mellon <arkanes at gmail.com> wrote:
> I haven't profiled this, so I'm committing a cardinal sin by
> speculating on performance-related results by just looking at the
> source, but here's my guess.
>
> wxPsuedoDC (wxPDC hereafter) has a list of PDC operations. It's in Z
> order, and a PDC operation is a list of actual drawing operations +
> some metadata.
>
> When you call SetID(), that just sets the ID that the next drawing
> operation will use.
>
> When you do a drawing operation, it calls AddToList, which scans the
> current list of operations for the current id, fails to find it, and
> then creates a new one. There's an optimization in the search for
> using the last ID, so repeated draws with the same ID are fast, but a
> draw with a new id is slow - there's a linear search for each id, so
> the time complexity for drawing n individual IDs is over O(n**2).
>
> Adding an index for id->node lookups is probably the best solution.
>
Attached is a patch to implement this. Some timing information below
(wx29() is with my patch, wx28() is without):
C:\>python -m timeit -s "import crash;dc =3D crash.wx29()" "crash.dotest(dc=
,1000)"
100 loops, best of 3: 7.91 msec per loop
C:\>python -m timeit -s "import crash;dc =3D crash.wx28()" "crash.dotest(dc=
,1000)"
100 loops, best of 3: 13.5 msec per loop
C:\>python -m timeit -s "import crash;dc =3D crash.wx29()" "crash.dotest(dc=
,10000)
"
10 loops, best of 3: 71.8 msec per loop
C:\>python -m timeit -s "import crash;dc =3D crash.wx28()" "crash.dotest(dc=
,10000)
"
10 loops, best of 3: 580 msec per loop
Note the linear speed of the 29 version, vs the quadratic speed of the
28 version. The patch does some internals refactoring - FindObjNode is
renamed to FindObject and returns the actual pdcObject instead of a
wxList::Node. This s
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pdc.patch
Type: application/octet-stream
Size: 8086 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20071=
001/f595b971/pdc.obj
More information about the wxpython-users
mailing list