ui.tools.inspector: improve performance for large arrays and hashtables.

Using trick suggested by @AlexIljin, we compute the longest key and then
set the column widths to be { length-of-longest-key 0 }.
modern-harvey2
John Benediktsson 2017-06-11 08:59:45 -07:00
parent 0fddbc2af1
commit e8cef24486
2 changed files with 25 additions and 10 deletions

View File

@ -99,7 +99,9 @@ M: image-name draw-cell nip draw-image ;
: compute-total-width ( gap widths -- total ) : compute-total-width ( gap widths -- total )
swap [ column-offsets drop ] keep - ; swap [ column-offsets drop ] keep - ;
: compute-column-widths ( table -- total widths ) GENERIC: compute-column-widths ( table -- total widths )
M: table compute-column-widths
dup rows>> [ drop 0 { } ] [ dup rows>> [ drop 0 { } ] [
[ drop gap>> ] [ initial-widths ] [ ] 2tri [ drop gap>> ] [ initial-widths ] [ ] 2tri
[ row-column-widths vmax ] with each [ row-column-widths vmax ] with each

View File

@ -1,14 +1,14 @@
! Copyright (C) 2006, 2009 Slava Pestov. ! Copyright (C) 2006, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors colors inspector namespaces kernel models fry USING: accessors arrays assocs classes combinators fonts fry
colors.constants models.arrow prettyprint sequences mirrors hashtables inspector io io.styles kernel math.vectors mirrors
assocs classes io io.styles arrays hashtables math.order sorting models models.arrow namespaces prettyprint refs sequences
refs fonts ui.tools.browser ui.commands ui.operations ui.gadgets sorting ui ui.commands ui.gadgets ui.gadgets.labeled
ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.slots ui.gadgets.panes ui.gadgets.scrollers ui.gadgets.slots
ui.gadgets.tracks ui.gestures ui.gadgets.buttons ui.gadgets.status-bar ui.gadgets.tables
ui.gadgets.tables ui.theme ui.gadgets.toolbar ui.gadgets.tables.private ui.gadgets.toolbar ui.gadgets.tracks
ui.gadgets.status-bar ui.gadgets.labeled ui.tools.common ui ui.gadgets.worlds ui.gestures ui.operations ui.theme
combinators ui.gadgets.worlds ui.theme.images ; ui.tools.browser ui.tools.common ;
IN: ui.tools.inspector IN: ui.tools.inspector
TUPLE: inspector-gadget < tool table ; TUPLE: inspector-gadget < tool table ;
@ -71,8 +71,21 @@ M: object make-slot-descriptions
M: hashtable make-slot-descriptions M: hashtable make-slot-descriptions
call-next-method [ key-string>> ] sort-with ; call-next-method [ key-string>> ] sort-with ;
TUPLE: inspector-table < table ;
! Improve performance for big arrays or large hashtables by
! only calculating column width for the longest key.
M: inspector-table compute-column-widths
dup rows>> [ drop 0 { } ] [
[ drop gap>> ]
[ initial-widths ]
[ keys longest "" 2array row-column-widths ] 2tri
vmax [ compute-total-width ] keep
] if-empty ;
: <inspector-table> ( model -- table ) : <inspector-table> ( model -- table )
[ make-slot-descriptions ] <arrow> inspector-renderer <table> [ make-slot-descriptions ] <arrow> inspector-renderer
inspector-table new-table
[ invoke-primary-operation ] >>action [ invoke-primary-operation ] >>action
monospace-font >>font monospace-font >>font
line-color >>column-line-color line-color >>column-line-color