Bug 489640 (gtk3SlowCombobox) - [GTK3] setting a lot of items to combobox is extremely slow (on gtk_combo_box_text_insert)
Summary: [GTK3] setting a lot of items to combobox is extremely slow (on gtk_combo_box...
Status: VERIFIED FIXED
Alias: gtk3SlowCombobox
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P2 major with 2 votes (vote)
Target Milestone: 4.9   Edit
Assignee: Leo Ufimtsev CLA
QA Contact:
URL:
Whiteboard: hasSnippet
Keywords: performance, triaged, usability
: 487271 536905 540805 (view as bug list)
Depends on:
Blocks: 527444 535255
  Show dependency tree
 
Reported: 2016-03-15 07:17 EDT by Thomas Singer CLA
Modified: 2018-11-06 10:40 EST (History)
14 users (show)

See Also:


Attachments
Sample code (1.43 KB, text/plain)
2016-03-15 07:18 EDT, Thomas Singer CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Singer CLA 2016-03-15 07:17:50 EDT
With the attached sample setting 169 items to the read-only combobox on SWT 4.614 takes around 10s on my Ubuntu 14.04 (and Ubuntu 15.10, too) causing the window to turn dark.
Comment 1 Thomas Singer CLA 2016-03-15 07:18:38 EDT
Created attachment 260308 [details]
Sample code
Comment 2 Sravan Kumar Lakkimsetti CLA 2016-03-15 08:00:49 EDT
On fedora 23 I am getting a time of 1.4 seconds with I20160314-2000.
Comment 3 Sravan Kumar Lakkimsetti CLA 2016-03-15 08:06:11 EDT
Can you please check this again with the latest build?
Comment 4 Thomas Singer CLA 2016-03-16 05:33:38 EDT
I've tried with 4.615 and this is MUCH snappier. It took only ~100ms.
Comment 5 Thomas Singer CLA 2016-03-16 07:25:58 EDT
Sorry, it looks like I've tried the wrong jars. Now I'm getting ~8s for 169 items again (with the latest 4.615 jars).
Comment 6 Thomas Singer CLA 2016-03-16 07:35:40 EDT
The fast time was with SWT_GTK3=0.
Comment 7 Thomas Singer CLA 2016-04-26 09:00:19 EDT
Were you able to reproduce the delay? I've tried the v4621 and it still is there.
Comment 8 Eric Williams CLA 2016-04-26 09:45:59 EDT
I can't reproduce this bug on Eclipse Neon, SWT master, Fedora 24 with GTK3.20. GTK2 insert time is ~21ms, GTK3 insert time is ~820 ms.
Comment 9 Thomas Singer CLA 2016-04-28 02:17:31 EDT
I'm getting these times on Ubuntu 14.04.

$ gnome-session --version
gnome-session 3.9.90
Comment 10 Thomas Singer CLA 2016-04-28 05:37:26 EDT
After having upgraded to Ubuntu 16.04 (Gnome 3.18) it is faster, but still takes 4100ms.
Comment 11 Thomas Singer CLA 2016-04-28 07:50:56 EDT
After updating Gnome to versiion 3.20 I'm getting now ~3700ms. Not that quick for only 171 items. I expect it to be below 100ms.
Comment 12 Eric Williams CLA 2016-10-04 12:12:15 EDT
Downgrading severity since this is a performance issue.

Also this seems CPU dependent. At home (AMD FX-8120) I am getting ~2000ms. At work (Intel Core i5 4300) the time was 820ms. No doubt GTK3 takes longer -- but the difference in the two times varies greatly depending on what CPU you have.
Comment 13 Thomas Singer CLA 2016-10-04 13:01:19 EDT
My tests were done on Core i5 machines.
Comment 14 Oleg Rachaev CLA 2016-12-11 02:52:46 EST
A have the same issue with Combo on Linux Mint 18.

Adding 1500 items tooks about 1-2 minutes on i5 cpu. A've tried setItems with no difference in performance.

This bug must have top priority to fix.
Comment 15 Oleg Rachaev CLA 2016-12-11 02:54:19 EST
Forgot to say swt 4.6.1 linux x64
Comment 16 Thomas Singer CLA 2017-11-18 05:32:30 EST
Increased the importance because this is a massive performance problem that prevents using GTK3 for real-world products.
Comment 17 Eric Williams CLA 2017-11-20 10:46:54 EST
My results as of this morning:

Intel® Core™ i7-6820HQ CPU @ 2.70GHz
SWT master
Fedora 27
GTK3.22.26

First run: ~800ms
Every run thereafter: ~1100ms

While GTK3 is slower than GTK2, I cannot reproduce the ~4000ms times. Please try a latest I-build on the latest Ubuntu. Maybe also try Unity vs. GNOME? Any data will help us narrow down the issue.
Comment 18 Thomas Singer CLA 2017-11-20 13:54:00 EST
Eric, we can't expect the end-users to upgrade their machines to make our application open dialogs in <1s instead of 10s - both is slow.

I'm just a Java developer - is there some GTK developer here that can verify whether this is an inherent problem of GTK3? Then it might be useful to replace the (SWT) combobox with something else, e.g. an ordinary button with a popup menu.
Comment 19 Eric Williams CLA 2017-11-20 14:17:10 EST
(In reply to Thomas Singer from comment #18)
> Eric, we can't expect the end-users to upgrade their machines to make our
> application open dialogs in <1s instead of 10s - both is slow.

I am not suggesting that. But so far no one on Fedora with basic GTK and GNOME can reproduce the issues -- this is why I am asking for someone with a modern Ubuntu to test on Unity and GNOME. The more information we have, the less time it will take us to reproduce the issue and fix the bug.

> I'm just a Java developer - is there some GTK developer here that can verify
> whether this is an inherent problem of GTK3? Then it might be useful to
> replace the (SWT) combobox with something else, e.g. an ordinary button with
> a popup menu.

Yes, next step would be to write a native snippet and see if the issue is reproducible.
Comment 20 Thomas Singer CLA 2017-11-21 03:01:07 EST
I've tried to open the preferences dialog in SmartSynchronize 3.4.12 (which contains 2 text encoding checkboxes) on my older Linux Notebook with Core i5 M460 @2.56GHz running Linux Mint 18.1 Serena, GTK 3.18.9 with Mint-X theme. With SWT_GTK3=1 it took ~12.6 seconds with the latest 4.830 SWT build from the master (2c1e42de2410e9ec). Even worse, it crashed with a NoSuchMethodError when trying to close the dialog, but this seems to be a different bug. With SWT_GTK3=0 it took ~2.5 seconds and did not crash.
Comment 21 Thomas Singer CLA 2017-11-21 03:01:53 EST
(In reply to Thomas Singer from comment #20)
> contains 2 text encoding checkboxes)

not checkboxes - comboboxes.
Comment 22 Alexander Levsha CLA 2017-11-21 09:03:20 EST
Linux Mint KDE 18.2 x64
GTK2 version 2.24.30
GTK3 version 3.18.9
SWT build I20171121-0020

Adding 500 items takes 91ms for GTK2, 11079ms for GTK3.
Performance degrades non-linearly, feels like O(x^2) or something.

As a more "real-world" example, filling 2 combos with Charset.availableCharsets() and TimeZone.getAvailableIDs() respectively takes 26+128ms on GTK2, 1251+17430ms on GTK3.
Comment 23 Eric Williams CLA 2017-11-21 16:51:09 EST
I've played around with a native snippet, and it looks like the issue is not present in native GTK (my GTK3 snippet runs in ~33ms). Leo (most likely) will look into this bug after the webkit2 port is done.
Comment 24 Leo Ufimtsev CLA 2017-11-22 09:16:12 EST
(In reply to Eric Williams from comment #23)
> I've played around with a native snippet, and it looks like the issue is not
> present in native GTK (my GTK3 snippet runs in ~33ms). Leo (most likely)
> will look into this bug after the webkit2 port is done.

Thanks for looking into this.

Btw, if you still have the native snippet, it would be useful to have it around somewhere. Would you be able to attach it here or submit it into the gtk native snippet test folder? (Probably push directly to master to avoid too much noise).

Thanks.
Comment 26 Leo Ufimtsev CLA 2018-05-25 10:56:12 EDT
(In reply to Eric Williams from comment #23)
> I've played around with a native snippet, and it looks like the issue is not
> present in native GTK (my GTK3 snippet runs in ~33ms). Leo (most likely)
> will look into this bug after the webkit2 port is done.

/Leo is finished with webkit2 port and is pulling out his bug spray.
Comment 27 Leo Ufimtsev CLA 2018-05-28 14:49:57 EDT
~Status update.

I did a code coverage.

When we call 'GTK.gtk_combo_box_text_insert (handle, i, null, buffer);', there are no signals being processed by SWT until the call is completed. (neither gtk2 or gtk3). I.e, the delay is internal to Gtk3.

I will need to figure out what's happening inside Gtk3 to figure out the delay.

As reported earlier, the insertion time gradually increases with number of items. Time per insert: 
insert 10 = 1 ms
insert 100 = 6ms
insert 500 = 28ms
insert 1000 = 62ms
Comment 28 Leo Ufimtsev CLA 2018-05-29 10:48:05 EDT
The root cause seems to be that setting wrap_width via:
GTK.gtk_combo_box_set_wrap_width(handle, 1);

Makes gtk re-compute the drop-down list size after every single insert.

Not setting this fixes the performance issue.

I'm looking into a way to fix/work around this.
Comment 29 Leo Ufimtsev CLA 2018-05-29 10:48:16 EDT
*** Bug 487271 has been marked as a duplicate of this bug. ***
Comment 30 Leo Ufimtsev CLA 2018-05-29 13:14:32 EDT
(In reply to Leo Ufimtsev from comment #28)
> The root cause seems to be that setting wrap_width via:
> GTK.gtk_combo_box_set_wrap_width(handle, 1);
> Makes gtk re-compute the drop-down list size after every single insert. 
> Not setting this fixes the performance issue.

I wrote a fix:
https://git.eclipse.org/r/#/c/123552/

Which basically disables wrap during active insertions and enables it lazily whn actually needed.

Before: 200 items took 1000ms.
Now   : 200 items took 10ms Gtk3   (23 ms on Gtk2 for comparison).

As per discussion with Alex.K, this is for 4.9 and at the moment will not be back ported to RC3 as the code is somewhat frozen.

~Awaiting review and merge.
Comment 31 Alexander Kurtakov CLA 2018-05-29 13:23:29 EDT
Sravan, should we consider this one for RC3 ?
Comment 32 Eric Williams CLA 2018-05-29 14:13:08 EDT
Running the bug snippet "Bug489640_ComboPerformanceTest", here are the before/after numbers with this patch:

BEFORE:

Setting widget.combo with 171 items
took 863 ms.
Setting widget.combo with 171 items
took 1318 ms.
Setting widget.combo with 171 items
took 1136 ms.
Setting widget.combo with 171 items
took 1112 ms.


AFTER:

Setting widget.combo with 171 items
took 23 ms.
Setting widget.combo with 171 items
took 415 ms.
Setting widget.combo with 171 items
took 407 ms.
Setting widget.combo with 171 items
took 418 ms.


Note that the subsequent additions (after the first insertion) take longer because all the items are removed and then added again.

IMO this is a pretty significant fix, and should be included in RC3.
Comment 33 Leo Ufimtsev CLA 2018-05-29 15:00:14 EDT
(In reply to Eric Williams from comment #32)

> AFTER:
> 
> Setting widget.combo with 171 items
> took 23 ms.
> Setting widget.combo with 171 items
> took 415 ms.
> Setting widget.combo with 171 items
> took 407 ms.
> Setting widget.combo with 171 items
> took 418 ms.


I noticed that the same problem was present when removing a lot of items.
I fixed this issue in patchset 4. Now adding & re-adding items takes +-20ms on every run.
Comment 34 Sravan Kumar Lakkimsetti CLA 2018-05-30 05:29:28 EDT
(In reply to Alexander Kurtakov from comment #31)
> Sravan, should we consider this one for RC3 ?

Since it is not a regression I think we should target 4.9. Also I feel the code changes are non trivial. Better not to push in 4.8
Comment 35 Leo Ufimtsev CLA 2018-05-30 11:56:37 EDT
(In reply to Sravan Kumar Lakkimsetti from comment #34)
> (In reply to Alexander Kurtakov from comment #31)
> > Sravan, should we consider this one for RC3 ?
> 
> Since it is not a regression I think we should target 4.9. Also I feel the
> code changes are non trivial. Better not to push in 4.8

That's a fair point. The patch ended up being somewhat bigger than initially anticipated.

Closing for now.

@Thomas Singer, if you could verify with latest nightly or maybe in a few weeks, that'd be great.
Comment 36 Thomas Singer CLA 2018-06-08 02:21:45 EDT
Perfect! With the latest build the times to add 171 items to the combobox was reduced from ~1.5s to ~30ms on my system, to replace the 171 items from ~2.2s to ~40ms.
Comment 37 Leo Ufimtsev CLA 2018-06-08 12:16:38 EDT
(In reply to Thomas Singer from comment #36)
> Perfect! With the latest build the times to add 171 items to the combobox
> was reduced from ~1.5s to ~30ms on my system, to replace the 171 items from
> ~2.2s to ~40ms.

Thank you for verifying!

I wonder if we have a simila issue with Tree's:
397042 – (TreeAddingNodesSlow) Adding tree nodes has N^2 complexity with respect to the number of children on GTK
https://bugs.eclipse.org/bugs/show_bug.cgi?id=397042

We should investigate.
Comment 38 Alexander Kurtakov CLA 2018-07-12 06:08:47 EDT
*** Bug 536905 has been marked as a duplicate of this bug. ***
Comment 39 Anton Krug CLA 2018-11-06 10:40:43 EST
*** Bug 540805 has been marked as a duplicate of this bug. ***