ObjectProfile / Roassal3

The Roassal Visualization Engine
MIT License
95 stars 52 forks source link

Slowdown caused by dirty rectangles and explicitRequirements #608

Open akevalion opened 6 months ago

akevalion commented 6 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 ] ] ]