pharo-graphics / Roassal

The Roassal Visualization Engine
MIT License
14 stars 8 forks source link

Slowdown caused by dirty rectangles and explicitRequirements #10

Closed JanBliznicenko closed 6 months ago

JanBliznicenko commented 8 months ago

There is a significant slowdown between between first and last commits in this new repo that seems to be caused by a combination of dirty rectangles and using explicitRequirements.

The slowdown is quite situational, but causes dragging elements in larger OpenPonk diagrams to degrade from quite fluent high-FPS experience to something hitting 1-3 FPS.

It is most noticable when dragging elements manually. Use RSRenderTreeExamples new example01BigVisualization131k and try to drag a single element around. In current master (or 3a0cdc0) it is quite sluggish while in b508334 with all methods with explicitRequirements removed, it is completely fluent.

To have some automatically executed example, I created 2 examples and created 4 images based on Pharo 11.

These are the two examples:

Boxes example:

|canvas boxes lines|
canvas := RSCanvas new.
boxes := (1 to: 5000) collect: [:i | RSBox new translateBy: i @ i; yourself ].
canvas addAll: boxes.
canvas open.

Smalltalk garbageCollect.

[ 
  40 timesRepeat: [boxes do: [ :each | each translateBy: 1@1 ]. ]
] timeToRunWithoutGC

Lines example:

|canvas boxes lines|
canvas := RSCanvas new.
boxes := (1 to: 100) collect: [ :i | RSBox new ].
canvas addAll: boxes.
(1 to: 100) do: [ :i | 
    (i to: 100) do: [ :j | 
        canvas add: (RSArrowedLine new from: (boxes at: i); to: (boxes at: j); withBorderAttachPoint; yourself).
        canvas add: (RSArrowedLine new from: (boxes at: j); to: (boxes at: i); withBorderAttachPoint; yourself).
     ]
].
canvas open.

Smalltalk garbageCollect.

[ boxes do: [ :each | each translateBy: 1@1 ] ] timeToRunWithoutGC

Boxes example:

Lines example:

Code that removes those explicitRequirements:

#( Roassal Numeric RTree ) do: [ :aPackageName |
    | regExp packages |
    regExp := '*' , aPackageName , '*'.
    packages := RPackageOrganizer default packages select: [ :each |
                    regExp match: each name ].
    packages do: [ :each |
        Transcript crShow:
            'Removing explicitRequirements from package ' , each name.
        each classes select: #isTrait thenDo: [ :eachClass |
            eachClass methods
                select: [ :eachMethod |
                    eachMethod sourceCode includesSubstring:
                        'self explicitRequirement' ]
                thenDo: #removeFromSystem ] ] ]
akevalion commented 8 months ago

Hi Jan, thank you very much for you feedback. Dirty rectangle is new experimental feature. It allows to users only redraw what has changed in the visualization. I will profile your examples and numbers to find a solution tomorrow

akevalion commented 8 months ago

Also please note that for big visualizations like example example01BigVisualization131k, you can use useRTree

Users of roassal can use the RTree or the List collection for drawing and search elements in the canvas space. You can use it in RSCanvas or in RSComposite.

The difference is huge.

|canvas boxes lines|
canvas := RSCanvas new.
canvas useList.
canvas useRTree.
"15K elements"
boxes := (1 to: 15000) collect: [:i | RSBox new translateBy: i @ i; yourself ].
canvas addAll: boxes.
canvas nodes @ RSDraggable new.
canvas open.

https://github.com/pharo-graphics/Roassal/assets/10532890/af645b4d-52c0-4791-9060-ba4d97356691

akevalion commented 8 months ago

@JanBliznicenko the problem is that now for drawing and events we use the shape collection, then specially if you are using big visualizations you have to use canvas useRTree.

Please let me know if this change work for your project so we can close this issue

akevalion commented 8 months ago

with @tesonep we saw the problem

JanBliznicenko commented 8 months ago

@akevalion Thank you for looking into that. Does useRTree help you for my examples? In my case, they actually take more time. It helps the OpenPonk itself, but it is still not as fast as it used to be before using dirty rectangles and explicitRequirements.

akevalion commented 6 months ago

Moved to Roassal3