On Wed, 21 Sep 2005 23:38:54 +0200 Alfredo Braunstein <[EMAIL PROTECTED]> wrote:

> Georg Baum wrote:
> 
> > I tried to reproduce this, and got similar results (including the
> speedup
> > if only one line is displayed), but only as long as I remained in one
> > paragraph. If I hit Enter from time to time everything was fine.
> > This looks as if the slowlyness is in the paragraph breaking
> algorithm.
> 
> Could the problem be that the painting algorithm has a precision of one
> paragraph --then if a big par is peeping at the top or bottom of the
> screen
> all of it is drawn (although possibly with NullPainter)?
> 
> Alfredo

That's part of the story. Another part is that a long long time ago, I tried
to implement a thing called Update::SinglePar. The idea was that, as long as
a paragraph's metrics don't change, you can type into it and _only it_ will be
updated.

That's the theory. Unfortunately, what is in CVS doesn't actually do this.
Still the whole screen gets updated, always, with rebreaking for every
paragraph. The singlepar code in metrics isn't actually used. My bad.

I tried the following modification, to make this stuff (1) work, and (2) 
work correctly as intended:


Index: BufferView_pimpl.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v
retrieving revision 1.595
diff -u -p -r1.595 BufferView_pimpl.C
--- BufferView_pimpl.C  15 Sep 2005 13:55:45 -0000      1.595
+++ BufferView_pimpl.C  21 Sep 2005 23:49:27 -0000
@@ -666,12 +666,12 @@ void BufferView::Pimpl::update(Update::f
                theCoords.startUpdating();
 
                // First drawing step
-               ViewMetricsInfo vi = metrics();
+               ViewMetricsInfo vi = metrics(flags & Update::SinglePar);
                bool forceupdate(flags & Update::Force);
 
                if ((flags & Update::FitCursor) && fitCursor()) {
                        forceupdate = true;
-                       vi = metrics(flags & Update::SinglePar);
+                       vi = metrics();
                }
                if (forceupdate) {
                        // Second drawing step
@@ -1340,7 +1340,9 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
        // Redo paragraphs above cursor if necessary
        int y1 = y0;
-       while (!singlepar && y1 > 0 && pit1 > 0) {
+       while (y1 > 0 && pit1 > 0) {
+               if (singlepar && (pit1 < cursor_.pit()))
+                       break;
                y1 -= text->getPar(pit1).ascent();
                --pit1;
                text->redoParagraph(pit1);
@@ -1364,7 +1366,9 @@ ViewMetricsInfo BufferView::Pimpl::metri
 
        // Redo paragraphs below cursor if necessary
        int y2 = y0;
-       while (!singlepar && y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+       while (y2 < bv.workHeight() && pit2 < int(npit) - 1) {
+               if (singlepar && (pit2 > cursor_.pit()))
+                       break;
                y2 += text->getPar(pit2).descent();
                ++pit2;
                text->redoParagraph(pit2);
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.307
diff -u -p -r1.307 text3.C
--- text3.C     16 Sep 2005 10:06:09 -0000      1.307
+++ text3.C     21 Sep 2005 23:49:28 -0000
@@ -1130,6 +1130,8 @@ void LyXText::dispatch(LCursor & cur, Fu
                if (!needsUpdate) {
                        // update only this paragraph
                        cur.bv().update(Update::SinglePar | Update::Force);
+               } else {
+                       cur.bv().update(Update::Force);
                }
 
                bv->updateScrollbar();
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.157
diff -u -p -r1.157 rowpainter.C
--- rowpainter.C        19 Sep 2005 11:18:20 -0000      1.157
+++ rowpainter.C        21 Sep 2005 23:49:28 -0000
@@ -792,8 +792,8 @@ void paintText(BufferView const & bv, Vi
 
        // and possibly grey out below
 //     lyxerr << "par descent: " << text->getPar(vi.p1).ascent() << endl;
-       if (vi.y2 < bv.workHeight())
-               pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - 
vi.y2, LColor::bottomarea);
+//     if (vi.y2 < bv.workHeight())
+//             pain.fillRectangle(0, vi.y2, bv.workWidth(), bv.workHeight() - 
vi.y2, LColor::bottomarea);
 }
 
As you see, rowpainter/paintText throws a spanner in the works, and I had to
suppress the painting of the bottom grey area. Here just done by brute force 
for proof of principle. If this really helps to produce a speedup, this
should be done cleanly, presumably by providing paintText with a singlepar
argument and making the suppression conditional upon it.

I also noted that metrics is called twice for every keystroke. Surely one of
those isn't necessary.

Sounds reasonable? Please test. Is it faster, or is it my imagination?

- Martin

Reply via email to