[racket-dev] racket/gui performance problem when using lots of items in table-panels

From: Marijn (hkBst at gentoo.org)
Date: Fri Nov 9 04:29:12 EST 2012

Hash: SHA1

On 19-07-12 16:59, Marijn wrote:
> 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?

So it seems a missing container-sequence block was causing unnecessary
extra problems. With it switching tabs is a lot less painful. However,
unfortunately trying to resize the window when showing the second tab
is still glacial/unusable.

Some clarifications:

1) I'm not claiming the problem is in the table-panel class. I'm just
using it as my vehicle to put lots of widgets on the screen. As far as
I can judge there is nothing in table-panel that could cause this
performance problem.

2) This is a test case reduced from a real program. Therefore the way
it goes about recreating widgets cannot be justified without the
context of the larger program. It is still not very small, but I did
not see a way to make it any smaller without destroying the essential
behavior. You can find a reduced test case for just the window
resizing problem below.

Slightly adapted code:

#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)
  #;(for ((child (send area get-children)))
    (send area delete-child child))
  (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 25)
(define nr-cols 20)

(define on-show-refresh-panel%
  (class table-panel%
    (init-field refresher)
    (define/override (on-superwindow-show shown?)
      (when shown?
        (displayln "refreshing!")
        (send this begin-container-sequence)
        (refresher this)
        (send this end-container-sequence)))

(define tab1
  (new panel% (parent root-tab-panel)))

(define (build-tab2 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)
              (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-rows ,nr-cols))
       (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)

The window resizing problem is also exhibited by this reduced test case:

#lang racket/gui

;(require (planet williams/table-panel:1:1/table-panel))
(require "table-panel.rkt")

(define frame
  (new frame%
       (label "Window Resize Perf Test")
       (width 500) (height 500)))

(define nr-rows 30)
(define nr-cols 25)

(define panel
  (new table-panel% (parent frame) (dimensions `(,nr-rows ,nr-cols)) ))

(for* ((r nr-rows)
       (c nr-cols))
  (new button%
       (parent panel)
       (label (format "~a,~a" r c))
       (stretchable-width #t)
       (stretchable-height #t)
        (lambda (button event)
          (printf "~a~n"
                  (send button get-label)))) )  )

(send frame show #t)

Thanks for any help,


Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/


Posted on the dev mailing list.