[racket-dev] racket/gui performance problem when using lots of items in table-panels
Here is an example of 30 x 20 buttons on a table-panel in a tab panel
that doesn't recreate the buttons and it changes between tabs without
much delay.
#lang racket/gui
(require (planet williams/table-panel/table-panel))
(define frame
(instantiate frame%
("Test")))
(define tab-panel
(instantiate tab-panel%
('("Tab 1" "Tab 2") frame)
(callback
(lambda (tp e)
(case (send tp get-selection)
((0) (send tp change-children (lambda (children) (list tab-1))))
((1) (send tp change-children (lambda (children) (list tab-2)))))))))
(define tab-1
(instantiate panel%
(tab-panel)
(min-width 400)
(min-height 400)))
(define tab-2
(instantiate table-panel%
(tab-panel)
(style '(deleted))
(dimensions '(30 20))))
(for* ((i (in-range 30))
(j (in-range 20)))
(instantiate button%
((format "~a, ~a" i j) tab-2)
(stretchable-width #t)
(stretchable-height #t)
(callback
(lambda (b e)
(printf "~a~n" (send b get-label))))))
(send frame show #t)
Doug
On Thu, Jul 19, 2012 at 9:08 AM, Doug Williams
<m.douglas.williams at gmail.com> wrote:
> I think the problem is the time it takes to create 600 buttons in this
> case, not the time needed to switch between the tabs. I'm not sure
> why you are recreating them each refresh. Am I missing something?
>
> Doug
>
> On Thu, Jul 19, 2012 at 8:59 AM, Marijn <hkBst at gentoo.org> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>>
>> I've been having some performance problems when using lots of items in
>> table-panels[1]. Switching tabs when running the following example
>> exhibits the problem. Can anything be done about it?
>>
>> Marijn
>>
>>
>> #lang racket/gui
>>
>> ;(require (planet williams/table-panel:1:1/table-panel))
>> (require "table-panel.rkt")
>>
>> ;;; The top-level frame
>> (define frame
>> (new frame%
>> (label "Table Panel Perf Test")
>> (width 500) (height 500)))
>>
>> (define (current-root-tab)
>> (vector-ref root-tab-vector (send root-tab-panel get-selection)) )
>>
>> (define (delete-all-children area)
>> (send area change-children
>> (lambda (children) '())) )
>>
>> (define (root-tab-callback tab-panel event)
>> (send root-tab-panel change-children
>> (lambda (children) (list (current-root-tab)))) )
>>
>> (define root-tab-panel
>> (new tab-panel%
>> (choices '()#;tab-names)
>> (parent frame)
>> (callback root-tab-callback)))
>>
>> (define nr-rows 30)
>> (define nr-cols 20)
>>
>> (define on-show-refresh-panel%
>> (class table-panel%
>> (init-field refresher)
>> (super-new)
>> (define/override (on-superwindow-show shown?)
>> (when shown?
>> (displayln "refreshing!")
>> (refresher)))
>> ))
>>
>> (define tab1
>> (new panel% (parent root-tab-panel)))
>>
>> (define (build-tab2)
>> (delete-all-children tab2)
>> (for* ((r nr-rows)
>> (c nr-cols))
>> (new button%
>> (parent tab2)
>> (label (format "~a,~a" r c))
>> (stretchable-width #t)
>> (stretchable-height #t)
>> (callback
>> (lambda (button event)
>> (printf "~a~n"
>> (send button get-label)))) ) ))
>>
>> (define tab2
>> (new on-show-refresh-panel% (parent root-tab-panel)
>> (style '(deleted))
>> (alignment '(center center))
>> (dimensions `(,nr-cols ,nr-rows))
>> (refresher build-tab2)))
>>
>> (define tabs
>> `((,tab1 . "Tab 1")
>> (,tab2 . "Tab 2")))
>>
>> (define tab-names (map cdr tabs))
>> (define root-tab-vector (list->vector (map car tabs)))
>>
>> (send root-tab-panel set tab-names)
>>
>> (send frame show #t)
>>
>>
>> [1]:http://planet.racket-lang.org/display.ss?package=table-panel.plt&owner=williams
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v2.0.19 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>>
>> iEYEARECAAYFAlAIIMoACgkQp/VmCx0OL2x3CgCbBhGkCCroHrEj1giTYA7KYhC4
>> 3sgAoMLUC6S+zouYY4kXm4HFca85odPG
>> =n8MG
>> -----END PGP SIGNATURE-----
>> _________________________
>> Racket Developers list:
>> http://lists.racket-lang.org/dev