After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 729832 - Creating new note is very slow (patch attached)
Creating new note is very slow (patch attached)
Status: RESOLVED FIXED
Product: gnote
Classification: Applications
Component: main
git master
Other Linux
: Normal normal
: ---
Assigned To: gnote-maint
gnote-maint
Depends on:
Blocks:
 
 
Reported: 2014-05-08 19:27 UTC by rincew314
Modified: 2014-05-11 16:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to use ustring iterator in TrieTree::find_matches() (918 bytes, patch)
2014-05-08 19:27 UTC, rincew314
committed Details | Review

Description rincew314 2014-05-08 19:27:36 UTC
Created attachment 276195 [details] [review]
Patch to use ustring iterator in TrieTree::find_matches()

When creating a new note with the "Automatically link to notes" option selected, gnote hangs for a few minutes with 100% CPU usage before popping up the new note window. I have quite a few large notes.

I compiled git master with debugging and caught it looping in TrieTree::find_matches() with the following stack:

  • #0 g_utf8_pointer_to_offset
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #1 gnote::TrieTree<std::weak_ptr<gnote::NoteBase> >::find_matches
    at trie.hpp line 216
  • #2 gnote::NoteManagerBase::find_trie_matches
    at notemanagerbase.cpp line 169
  • #3 gnote::NoteLinkWatcher::highlight_in_block
    at watchers.cpp line 929
  • #4 gnote::NoteLinkWatcher::on_note_added
    at watchers.cpp line 798
  • #5 sigc::internal::signal_emit1<void, std::shared_ptr<gnote::NoteBase> const&, sigc::nil>::emit
    at /usr/include/sigc++-2.0/sigc++/signal.h line 1010
  • #6 emit
    at /usr/include/sigc++-2.0/sigc++/signal.h line 2781
  • #7 operator()
    at /usr/include/sigc++-2.0/sigc++/signal.h line 2789
  • #8 gnote::NoteManagerBase::create_new_note
    at notemanagerbase.cpp line 347
  • #9 gnote::NoteManager::create_new_note
    at notemanager.cpp line 305
  • #10 gnote::NoteManagerBase::create_note_from_template
    at notemanagerbase.cpp line 265
  • #11 gnote::NoteManager::create_note_from_template
    at notemanager.cpp line 335
  • #12 gnote::NoteManagerBase::create_new_note
    at notemanagerbase.cpp line 307
  • #13 gnote::NoteManager::create_new_note
    at notemanager.cpp line 293
  • #14 gnote::NoteManagerBase::create
    at notemanagerbase.cpp line 239
  • #15 gnote::NoteManagerBase::create
    at notemanagerbase.cpp line 234
  • #16 gnote::NoteRecentChanges::new_note
    at recentchanges.cpp line 294
  • #17 gnote::Tray::on_new_note_activate
    at tray.cpp line 363
  • #18 Glib::SignalProxyNormal::slot0_void_callback(_GObject*, void*)
    from /usr/lib/x86_64-linux-gnu/libglibmm-2.4.so.1
  • #19 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #20 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #21 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #22 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #23 gtk_widget_activate
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #24 gtk_menu_shell_activate_item
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #25 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #26 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #27 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #28 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #29 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #30 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #31 ??
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #32 gtk_main_do_event
    from /usr/lib/x86_64-linux-gnu/libgtk-3.so.0
  • #33 ??
    from /usr/lib/x86_64-linux-gnu/libgdk-3.so.0
  • #34 g_main_context_dispatch
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #35 ??
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #36 g_main_context_iteration
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #37 g_application_run
    from /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
  • #38 gnote::Gnote::main
    at gnote.cpp line 103
  • #39 main
    at main.cpp line 35


The TrieTree::find_matches() function appears to be looking up characters in the UTF-8 text one at a time, which means rescanning from the beginning of the string each time (since you can't randomly access characters in UTF-8).

Attached is a patch to use a ustring iterator instead, which improves the note creation time to essentially instant in my case.
Comment 1 Hubert Figuiere (:hub) 2014-05-08 20:56:17 UTC
Good catch. Totally make sense.

It happen that "add_keyword" has the same issue.
Comment 2 Aurimas Černius 2014-05-11 16:31:42 UTC
Nice catch. Committed.