Am 04.05.2010, 00:44 Uhr, schrieb Martin Liebscher  
<[email protected]>:

> Hi,
>
> I'm try the draw a tree like figure with fc2. Most things are working
> well so far but adding many nodes (> 500 rectangles and 500 lines) to
> the canvas is really slow. It takes up to 40 sec. Panning, Moving around
> later is fast enough...
>
> I'm sure I did something in the wrong way. I'm simply looping over all
> objects calling e.g. createRectangle ...
>
> for id, pos in posistions.items():
>             node_set[id] = canvas.createRectangle( (32, 32),\
>                    name=str(id), pos = pos, look = look )
>
> Are there things that can be done better? Something like batch
> operation?

Hello Martin,

at the current stage it is indeed very slow to create lots of new nodes. I  
suspect (and I think I already profiled) the automatic change detection  
mechanic. This allows you to do

line.length = newValue

and the canvas will know it has to redraw itself. Now this extends to all  
kinds of objects like lines, rectangles, looks, nodes etc.. Now when you  
create 1000 new nodes this creates a bunch of objects each with subobjects  
and attributes which all detect changes and send a "needs updating" event.  
Just sending all those events is what takes up such a long time.

There are opportunities to enhance this scheme, ideas:

- objects should maybe send events directly to the canvas instead of  
sending events to their parent objects which then relay to the canvas.  
Might cause problems with render to surface nodes.
- once the canvas is dirty, no dirty events are sent at all. This should  
reduce the cost of sending events by a huge factor.
- allow a way to make this scheme pluggable. I.e. you can switch between  
automatic updating and something like

line.length = newValue
canvas.updateRequired()

In the next two months (maybe longer) I don't have the time to implement  
any of these features myself. They'd be great to have since other users  
have also been faced with the same problem. If you want to dig into this I  
can give you assistance with solving this problem.

-Matthias
_______________________________________________
FloatCanvas mailing list
[email protected]
http://paulmcnett.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to