Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Speeding up ComposableModel new openWithSpec (in Pharo v3)

I needed a GUI with 81 boxes where the user can choose to input one single number (is a board of a game).

So i have subclassed a ComposableModel with 81 instance variables each one initializing to a new TextInputFieldModel instance.

The problem is it takes about 6 seconds to open. Why it takes so long to open 81 text boxes? Is there something i could do to speed the opening?

like image 744
Laura Avatar asked Mar 18 '23 11:03

Laura


1 Answers

You can use the Profiler for this. I have tried to recreate your UI requirement and run it inside the Tools -> Time Profiler. This is the Code:

| specArray widgets view layout |
" Configure the Spec models "
specArray := OrderedCollection new: 81 * 2.
1 to: 81 do: [ : index | specArray 
    add: ('textInput' , index asString) asSymbol;
    add: #TextInputFieldModel ].
view := DynamicComposableModel new
        instantiateModels: specArray;
        extent: 300@800;
        title: 'Title'
        yourself.
" Configure the Spec layout "
widgets := specArray reject: [ : ti | ti = #TextInputFieldModel ].
layout := SpecLayout composed
        newColumn: [ : r | 
        widgets doWithIndex: [ : ti : index | r add: ti ] ];
        yourself.
" Set up the widgets "
widgets doWithIndex: [ : each : index | (view perform: each) text: index asString  ].
" Open the Window "
(view openWithSpecLayout: layout) delete.

As you can see in the screenshot, most time is spent in TextInputFieldModel>>defaultEntryCompletion so you can try to speed up that section (unfortunately the method is undocummented)

enter image description here

If you apply the Leandro's suggestion you can speed up the from

  • 3902 tallies, 3912 msec.
  • 3916 tallies, 3927 msec.

to

  • 1985 tallies, 1988 msec.

The code in TextInputFieldModel>>defaultEntryCompletion would be:

defaultEntryCompletion

    | applicants |
    applicants := (Array streamContents: [:strm | 
                    Smalltalk globals keysDo: [ : each | (each notEmpty and: [each first canBeGlobalVarInitial]) 
                        ifTrue: [ strm nextPut: each ] ] ]) sort.

    ^ EntryCompletion new
                dataSourceBlock: [:currText | applicants];
                filterBlock: [:currApplicant :currText | currText size > 3
                        and: [currApplicant asUppercase includesSubstring: currText asString asUppercase]].
like image 146
Hernán Avatar answered Mar 31 '23 19:03

Hernán