[Geany-Devel] Making Geany faster (reducing latency to typed text)

Evandro Borracini evandro.borracini at gmail.com
Sat Nov 24 13:48:28 UTC 2012


Hi Lex,

Thanks for your reply.
In the original code, document_redo/undo_add() calls
document_set_text_changed(doc, TRUE) so it's hardcoded with changed=TRUE
and it would always call the ui updates even if we added an if (changed ==
TRUE)...

void document_set_text_changed(GeanyDocument *doc, gboolean changed)
{
    g_return_if_fail(doc != NULL);

    doc->changed = changed;

    if (! main_status.quitting)
    {
        ui_update_tab_status(doc);
        ui_save_buttons_toggle(changed);
        ui_set_window_title(doc);
        ui_update_statusbar(doc, -1);
    }
}

Interestingly, is that I still see updates in the sidebar, buttons, windows
title and status bar after commenting out the call to
document_set_text_changed() inside document_redo/undo_add().  So, I think
it's called elsewhere.

I'll study the code a bit more to try to understand how the ui updates
works.

Another interesting point is that only ui_update_tab_status(doc) creates a
noticeable latency.
The other functions: ui_save_buttons_toggle(changed),
ui_set_window_title(doc), ui_update_statusbar(doc, -1) seem to be fast.

Thanks again and regards,

Evandro



2012/11/24 Lex Trotman <elextr at gmail.com>

> On 24 November 2012 16:15, Evandro Borracini
> <evandro.borracini at gmail.com> wrote:
> > Hi,
> >
> > I started using Geany a couple of weeks ago and I noticed a slower
> response
> > to typed text than my previous editor Scite. Running both editors at the
> > same time, it was noticeable to me that Geany had a slightly longer
> latency
> > time for printing the characters on the screen (and/or for moving the
> cursor
> > to the next line after hitting the Enter key).
> >
> > Well, I think that might not be noticeable to most of users (since they
> run
> > Geany on fast machines) but It is annoying me because I'm working on a
> > shared server (which most of time is very loaded), making the latency
> even
> > bigger. So, I've been trying to identify the cause of the latency.
> >
> > After some experiments and I think I could find the cause and an
> workaround.
> > I just need some help from you guys for getting a final solution.
> >
> > I see that the latency is caused the following sequence of function
> calls:
> >
> > editor.c: on_editor_notify()  inside "switch (nt->nmhdr.code) ... case
> > SCN_MODIFIED" :
> >         document_undo_add(doc, UNDO_SCINTILLA, NULL);  (file: document.c)
> >             document_set_text_changed(doc, TRUE); (file: document.c)
> >                 ui_update_tab_status(doc) (file: ui_utils.c)
> >                    sidebar_openfiles_update(doc); (file: ui_utils.c)
> >
> >
> > It seems that the latency is because sidebar_openfiles_update() is called
> > too frequently (apparently at each typed key). I've made an experiment by
> > commenting out the call to ui_update_tab_status(doc) (insided
> > document_set_text_changed() ) and I got Geany as sharp as Scite!!!    :-)
> >
> > I'd like to propose the fix below (please find the patch in the end of
> this
> > message). It worked fine for me but since I'm not much familiar with
> Geany
> > source code, I need you guys to review it.
> >
> > Could you guys please review my fix? Does any of you see any better
> > solution?
> >
> > Please notice that I'm changing two functions:
> > document_undo_add() - reduced the latency while typing text
> > document_redo_add() - reduced the latency for the undo operation (CTRL+Z)
> >
> > Thanks in advance and regards,
> >
> > Evandro
> >
> >
> >
> > diff -Naurp geany-0.20/src/document.c geany-0.20_fast/src/document.c
> > --- geany-0.20/src/document.c    2012-11-23 20:22:22.564735000 -0800
> > +++ geany-0.20_fast/src/document.c    2012-11-23 20:28:17.535008000 -0800
> > @@ -2676,7 +2676,9 @@ void document_undo_add(GeanyDocument *do
> >
> >      g_trash_stack_push(&doc->priv->undo_actions, action);
> >
> > -    document_set_text_changed(doc, TRUE);
> > +    /* document_set_text_changed(doc, TRUE); */
>
> Hi,
>
> I don't think removing a lot of UI update calls is the right solution
> unless you can show that they are done elsewhere.  The things that are
> done by these calls must be done somewhere to make the UI respond
> correctly to document changed status.
>
> A possible better solution (that I have not tested) is for
> document_set_text_changed() to only call the UI updates if the changed
> status is changed.
>
> Cheers
> Lex
>
> > +    doc->changed = TRUE;
> > +
> >      ui_update_popup_reundo_items(doc);
> >  }
> >
> > @@ -2840,7 +2842,9 @@ static void document_redo_add(GeanyDocum
> >
> >      g_trash_stack_push(&doc->priv->redo_actions, action);
> >
> > -    document_set_text_changed(doc, TRUE);
> > +    /* document_set_text_changed(doc, TRUE); */
> > +    doc->changed = TRUE;
> > +
> >      ui_update_popup_reundo_items(doc);
> >  }
> >
> >
> >
> > _______________________________________________
> > Devel mailing list
> > Devel at lists.geany.org
> > https://lists.geany.org/cgi-bin/mailman/listinfo/devel
> >
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.geany.org/pipermail/devel/attachments/20121124/5a378cdd/attachment.html>


More information about the Devel mailing list