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 317125 - Deleting big range of text with tags in GtkTextBuffer is incredibly slow
Deleting big range of text with tags in GtkTextBuffer is incredibly slow
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTextView
2.8.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2005-09-24 19:49 UTC by Yevgen Muntyan
Modified: 2011-02-04 16:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case. It's big (52.05 KB, application/x-bzip2)
2005-09-24 19:50 UTC, Yevgen Muntyan
  Details
profile.txt (347.89 KB, text/plain)
2005-09-24 19:56 UTC, Paolo Borelli
  Details
profile.png (58.91 KB, image/png)
2005-09-24 19:57 UTC, Paolo Borelli
  Details
a patch (2.19 KB, patch)
2005-10-09 05:30 UTC, Matthias Clasen
none Details | Review

Description Yevgen Muntyan 2005-09-24 19:49:28 UTC
Attached is a test case demonstrating the problem. If a big buffer has tags  
applied in many places (there are about 70 tags in total, and the buffer is  
9000 lines long, in this test case), then deleting range of text is incredibly  
slow - in attached test case it takes minutes.   
It's not really clear what 'big' and 'lot' mean. Attached test case is a dump  
of real text buffer with syntax highlighting inside. With some highlighting,  
deleting is not that slow; with some highlighting it is. I.e. just size of  
buffer and just number of places where tags are applied does not necessarily  
lead to slow deletion. But I could not track it down to something meaningful.  
Interesting thing is that removing tags from buffer before deleting makes  
things fast - it takes seconds. To see this, change '#if 0' to '#if 1' in the  
source.  
  
To reproduce:  
1) compile attached file;  
2) run it;  
3) press ctrl-a to select all, and press backspace.  
Result: it freezes for minutes.  
  
It reproduces in gtk-2.6.4 and gtk from gtk-2-8 cvs branch.
Comment 1 Yevgen Muntyan 2005-09-24 19:50:46 UTC
Created attachment 52602 [details]
Test case. It's big
Comment 2 Paolo Borelli 2005-09-24 19:56:03 UTC
I ran sysprof of muntyan's testcase, since he doesn't have a kernel > 2.6.11

Here is the dump and a png showing the bottleneck (at least according to sysprof)
Comment 3 Paolo Borelli 2005-09-24 19:56:57 UTC
Created attachment 52603 [details]
profile.txt
Comment 4 Paolo Borelli 2005-09-24 19:57:32 UTC
Created attachment 52604 [details]
profile.png
Comment 5 Matthias Clasen 2005-10-09 05:30:33 UTC
Created attachment 53247 [details] [review]
a patch

Can you see if the attached patch helps ? 
It should eliminate the quadratic behaviour (in the number of deleted tags)
Comment 6 Yevgen Muntyan 2005-10-10 10:01:06 UTC
Yes, it does help. I tried big files I have here, and everything worked fine.
Speed is about the same as speed of deleting all tags, i.e. it's great.
Comment 7 Paolo Borelli 2005-10-10 10:07:50 UTC
just to confirm, works here too and I haven't noticed bugs/regressions
Comment 8 Matthias Clasen 2005-10-11 17:04:32 UTC
2005-10-11  Matthias Clasen  <mclasen@redhat.com>

	* gtk/gtktextbtree.c (_gtk_text_btree_delete): Try to match an off 
	toggle here with the matching on toggle if it immediately follows. 
	This is a common case, and handling it here prevents quadratic blowup 
	in cleanup_line() below.  (#317125)

	* gtk/gtktextsegment.h: 
	* gtk/gtktextsegment.c (_gtk_char_segment_new_from_two_strings): Pass
	the character counts into this function instead of computing them