Re: Speedup canvas itemconfigure -fill for many polygons.



On Mar 30, 10:18 pm, max vorticity <max.vortic...@xxxxxxxxxxx> wrote:
I had an error in my analysis so the slowness is not really
attributable to the itemconfigure command.  So forget my original post
except that when using a lot of tags, it is much slower to address the
items by individual tags for each polygon than by the original canvas
id

Yes, this is due to the fact that lookup by id uses a hashtable, while
lookup by tag implies a linear search.
But at the same time, the internal iterator over the items of a tag
has a small linear constant (because it's in C). More precisely, if a
canvas has N items, of which K hold the tag T, then

.c itemconfigure T -fill red

will take a*N+b*K, where a and b are rather small (C iteration).
While if you store the same K ids in a list l, then

foreach i $l {.c itemconfigure $i -fill red}

will take c*K, where c is much larger than a and b (Tcl iteration)

So, there is a point of equilibrium where tags become faster than
individual ids to handle groups of items.
Reaching this regime implies to have tags with many items each (large
K), that's why I asked about your ability to quantize the colors. But
I admit that other overheads must be taken into account, since tag
handling implies to use addtag and dtag frequently...

id's appears to be noticably faster.  My application has over 80000
canvas items and I amazed at how well the canvas does.

Case closed, then ?

-Alex
.



Relevant Pages

  • Re: creating GUI of lines
    ... canvas boundaries, the lines are discontinuous. ... when we configure the widget, i need to change the line ... etc, is just to use a single text widget, and text tags to identify ...
    (comp.lang.tcl)
  • Re: XOR drawing on Tk canvas?
    ... >>with Tk's canvas than you could with bitmaps and XOR. ... >>use these tags to refer to the items on the canvas. ... on all pieces say, NORMAL or HIGHLIGHT, as well as indiviauald tags N7 & H7) ...
    (comp.lang.tcl)
  • Re: WxInter
    ... all things a tk canvas can do very easily... ... or on a group of items via tags. ... ## Event binding on several objects grouped via a tag ... automatically the bindings created on its tag. ...
    (comp.lang.python)
  • Re: selecting a good background color
    ... With busy data, it can easy have 2 to 3 thousand items. ... I think all of my canvas items have at ... I use tags extensively also. ... the tags represent a geometry ...
    (comp.lang.tcl)
  • Re: WxInter
    ... >>individually, or group them with tags, or knowing which items are at a ... all things a tk canvas can do very easily... ... your own app. ... Check out my FloatCanvas for wxPython: ...
    (comp.lang.python)