Apple Newton Internet Enabler Especificações Página 18

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 24
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 17
June 1996 Newton Technology Journal
18
Techniques for writing faster code are always of interest to NewtonScript
developers. Faster implementations open new avenues of functionality for
applications – what was once unthinkably slow can become marketably fast.
Some speed techniques capitalize on details of the execution environment.
For example, in the NewtonScript interpreter, it is quicker to iterate through
the elements of an array with foreach than it is with an explicit for loop
[McKeehan & Rhodes, 1995]. Careful attention to these details can lead to
significant performance improvements. Other speed techniques are
applicable to any execution environment. For example, it is faster to move
invariant statements outside of loops to avoid repeating them unnecessarily.
This article explores a combination of techniques like these to speed view
scrolling by a factor of four.
SCROLLING
A common task in a Newton application is to present a scrollable list of items
to the user for their inspection and/or selection. Figure 1 depicts the sample
application used to demonstrate the ideas in this article. On a Newton
MessagePad 120, the application shows 14 of 100 items. It scrolls by one
item when the user taps the Up or Down arrow. (The current Newton User
Interface Guidelines recommend scrolling by one screenful minus one item.
This policy may reflect assumptions about scrolling speed.) Each item
includes a check box, an icon formatted to look like a button, two text
elements, and a gauge. Hypothetically, when the user taps a single item, the
application would respond in some way, perhaps by toggling the checkbox
or switching to a layout to display the item in more detail. The sample
application assumes that data for the items are in an array. If an application
keeps its data in soup entries, slightly different techniques are needed. The
Newton DTS sample code “True Grid” demonstrates similar ideas in the
context of soups.
Figure 1. Sample Application with Scrolling Views
USING AN AGGREGATE PROTO AND
setOrigin
A simple and robust implementation for scrolling a list of items is to
construct a proto that depicts a single item. The proto includes five
children: a checkbox, a picture view, two static texts, and a gauge. These
children initialize themselves using a
viewSetupFormScript
. In this
script they inherit a slot value from the proto’s item and set up their display
accordingly. Construct a parent view (call it P) with one child for each item
to be displayed (say there are N of them, for example, 100). P has its
clipping flag set and is sized large enough to show one screenful of items
(say there are S of them, for example, 14). The base application view
responds to
viewScrollUpScript
and
viewScrollDownScript
messages by sending
setOrigin
to P. This changes P’s vertical offset by the
amount corresponding to the height of one child. Newton’s view system
automatically shows a different subset of the items depending on where the
user has scrolled to.
To test how fast this implementation is, the application was sent a series
of commands from the Newton Toolkit Inspector window:
open
,
viewScrollDownScript
10 times,
viewScrollUpScript
10 times, and
close
. Each message was followed by a call to
RefreshViews
to force
Newton’s view system to update. This sequence of commands was
highlighted and evaluated all at once. Times reported here are measured by
profiling and are rounded to the nearest tenth of a second.
To its credit, this affords fast scrolling. In a test using data similar to that
shown in Figure 1, it took only 9.8 seconds to scroll down by 10 items and
back up by 10 items. The N views corresponding to each item were
constructed when P was opened, and the view system can rapidly move the
child views into and out of the clipping region of P. This implementation is
also easy to implement correctly; P can set up all N of the children at one
time in its
viewSetupChildrenScript
by assigning each of them one
item to display. Each child proto only has to initialize itself with a
viewSetupFormScript
. The price for this performance is the overhead
associated with creating all N of the child views when P is opened. This
creation takes time and heap space: 3.6 seconds to open and 32K of heap (as
measured by GC and Stat, rounded to the nearest K). Along both of these
dimensions this implementation is the worst of those considered here.
USING AN AGGREGATE PROTO AND
syncChildren
Another alternative is to build a parent view P with only S child views (that is,
only as many as can be displayed at one time). As before, P is large enough
to show one screenful but need not clip. The base view forwards the
viewScrollUpScript
and
viewScrollDownScript
messages to P. In
turn P sends itself the
syncChildren
message. In response to this,
Newton’s view system sends P the
viewSetupChildrenScript
message
Parent view P
S children views
visible at one
time
Caching for Maximum View Scrolling Performance
by Jeffrey C. Schlimmer, Washington State University
NewtonScript Techniques
Vista de página 17
1 2 ... 13 14 15 16 17 18 19 20 21 22 23 24

Comentários a estes Manuais

Sem comentários