High performance text component

André Thieme a.thieme at freenet.de
Wed Sep 5 16:43:23 PDT 2012


Am 05.09.2012 22:16, schrieb Felipe Heidrich:

> This is an open question because Text already includes some of the
> properties that are used during the paragraph layout. For example,
> Text has wrapping width and text alignment, if we choose to reuse
> Text that will mean that these properties will be ignored if they are
> set in Text that is parent by a Paragraph.


Plus there are currently still two challenges regarding the Text.
One is the main challenge, and the second one just intensifies it.

The main challenge is that Texts are too slow, when very many of them
are visible at the same time. If I would like to program something like
OpenOffice or Word or Eclipse with JavaFX, I am facing the problem that
a user may maximize his/her text input pane in those editors, and type
something that requires each single character to be a unique Text
instance. With a small font we can easily fit 20k chars on a single
monitor. If the user even has two monitors we might have 40k Text
instances, that are visible at the same time, without scrolling.

Just write a simple test application which creates 20k Spans or Texts
and displays them in some pane, and try to resize the window. It will
be slow. In principle this is just text, and whatever we do to it, it
should always display with 60 FPS, even on slower systems.
Currently it is more like 2 FPS or something like that.

If you now do this with LCD Text, then it gets extremly slow.


I implemented a prototype TextEditor component, with all those nice
suggestions that I got here. It uses Text instances and a virtual Pane,
with ScrollBars that my code manages. For typical and realistic cases,
and without LCD text, this TextEditor component scrolls very smoothly.
I also can add hundreds of thousands of Text. No problem.
But in my scenarios max 1250 Text instances can be visible at any given
time. This is fine for real world code. But I can not prevent users to
try out the limits of the editor. They could alternate a few characters
that all require to be rendered as a single Text instance. For example,
say that the questionmark is displayed in green, digites in black, and
parens in red. The user could type
(?0)?1(?2)?3(?4)?5(?6)?7(?8)?9(?0)?1(?2)... and so on.

Here I can not compact several chars into a single Text instance.
If the user typed
1 2 3 4 5
then the renderer could figure out that digits are all black, and can do
t.setText("1 2 3 4 5");
So a series of Texts that would all have the same color, and font and
bold/italic style, or are striked through, underlined, overlined,
whatever — they can all be compacted into a single Text.
But endusers may produce nonsense inputs that force the renderer to
output single-char Text instances. 40k on one screen.
And the user wants to be able to read them clearly and requires LCD
text. Here we are at 0.01 FPS or so, while it should be 60, and only
because JFX and the typical monitor limits it to this value.

I would be more interested in the most low-level method call that I can
make to get text on the screen, in the most efficient way.

I already asked this earlier: how does the Label or Text component draw
a String? I could not find this in the source code of JFX. But at some
point you have to fall back to some low level calls.


Regards,
André


More information about the openjfx-dev mailing list