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 664124 - Clean up updating of network menu
Clean up updating of network menu
Status: RESOLVED FIXED
Product: gnome-shell
Classification: Core
Component: network-indicator
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
: 665838 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2011-11-15 16:35 UTC by Giovanni Campagna
Modified: 2011-12-16 07:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Network Menu: update the UI only when really needed (8.34 KB, patch)
2011-11-15 16:36 UTC, Giovanni Campagna
reviewed Details | Review
Network Menu: update the UI only when really needed (7.94 KB, patch)
2011-11-19 18:04 UTC, Giovanni Campagna
committed Details | Review
NetworkMenu: fix number of visible networks (1.28 KB, patch)
2011-11-19 18:04 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2011-11-15 16:35:41 UTC
Current code for updating network menu when AP change is messy, to do only the minimum work needed to keep everything updated at all times.
This has two problems:
1) We keep the UI updated even when it's not needed
2) We have different code paths in different situations, which leads to situations like bug 661793

The following patch is an attempt to fix this issue, tackling from the opposite side. I think it should not worsen performance much, but some testing in crowded areas would help.
Comment 1 Giovanni Campagna 2011-11-15 16:36:20 UTC
Created attachment 201456 [details] [review]
Network Menu: update the UI only when really needed

By using Main.queueDeferredWork, we can ensure that most of the
menu contents (in particular, the heaviest parts like the list of
wifi networks) are not updated immediately as we receive signals
from NetworkManager. Instead, the menu is rebuilt some time later,
or as soon as the user opens the menu.
This means that it is no longer needed to optimize for the
access-point-added case, replacing a lot of buggy code with a safer
call to _queueCreateSection, which in turn should ensure that the
more menu, if existing, is always at the end and that at most 5 networks
are visible outside it.
Comment 2 Jasper St. Pierre (not reading bugmail) 2011-11-15 18:08:58 UTC
Review of attachment 201456 [details] [review]:

::: js/ui/status/network.js
@@ +1544,3 @@
             let apObj = this._networks[j];
+            if (apObj == this._activeNetwork) {
+                activeOffset--;

This looks like an unrelated bug fix?
Comment 3 Giovanni Campagna 2011-11-19 13:36:42 UTC
(In reply to comment #2)
> Review of attachment 201456 [details] [review]:
> 
> ::: js/ui/status/network.js
> @@ +1544,3 @@
>              let apObj = this._networks[j];
> +            if (apObj == this._activeNetwork) {
> +                activeOffset--;
> 
> This looks like an unrelated bug fix?

Only partially: the main purpose of this bug is getting 5, and always 5, networks in the menu, plus a More...
This fix is needed for that (otherwise, you always get 4 of them)
Comment 4 Jasper St. Pierre (not reading bugmail) 2011-11-19 13:56:56 UTC
I'd like it in a separate patch. And what's wrong with:

    if (this.section.numMenuItems > NUM_VISIBLE_NETWORKS)
Comment 5 Giovanni Campagna 2011-11-19 18:00:19 UTC
(In reply to comment #4)
> I'd like it in a separate patch. And what's wrong with:
> 
>     if (this.section.numMenuItems > NUM_VISIBLE_NETWORKS)

What do you mean by that? (or where would that apply?)
Comment 6 Giovanni Campagna 2011-11-19 18:04:01 UTC
Created attachment 201708 [details] [review]
Network Menu: update the UI only when really needed

By using Main.queueDeferredWork, we can ensure that most of the
menu contents (in particular, the heaviest parts like the list of
wifi networks) are not updated immediately as we receive signals
from NetworkManager. Instead, the menu is rebuilt some time later,
or as soon as the user opens the menu.
This means that it is no longer needed to optimize for the
access-point-added case, replacing a lot of buggy code with a safer
call to _queueCreateSection, which in turn should ensure that the
more menu, if existing, is always at the end and that at most 5 networks
are visible outside it.
Comment 7 Giovanni Campagna 2011-11-19 18:04:24 UTC
Created attachment 201709 [details] [review]
NetworkMenu: fix number of visible networks

When placing networks in _createSection, we were taking in
consideration that _activeNetwork is always first, by adding 1,
but then kept this offset also for networks following it (normally,
all of them, since _activeNetwork is also the most recently used),
that instead should not be affected by the movement.
This resulted in the menu showing 4 networks + More... instead of
5.
Comment 8 Jasper St. Pierre (not reading bugmail) 2011-11-19 19:02:15 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > I'd like it in a separate patch. And what's wrong with:
> > 
> >     if (this.section.numMenuItems > NUM_VISIBLE_NETWORKS)
> 
> What do you mean by that? (or where would that apply?)

I mean that instead of this activeOffset nonsense and checking the indexes, we just check the amount of menu items. that have been inserted so far.
Comment 9 Matthias Clasen 2011-12-07 13:04:21 UTC
Any update on this ? I'd love to see the network menu work better in 3.4...
Comment 10 Giovanni Campagna 2011-12-07 14:10:32 UTC
(In reply to comment #8)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > I'd like it in a separate patch. And what's wrong with:
> > > 
> > >     if (this.section.numMenuItems > NUM_VISIBLE_NETWORKS)
> > 
> > What do you mean by that? (or where would that apply?)
> 
> I mean that instead of this activeOffset nonsense and checking the indexes, we
> just check the amount of menu items. that have been inserted so far.

While that would be cleaner, it would become O(N^2) to build the menu (which in turn becomes O(N^3) if the menu is rebuilt each time a new AP is found).
Given all the performance problems around that code, I'd avoid that, if possible.
Comment 11 Jasper St. Pierre (not reading bugmail) 2011-12-07 14:12:50 UTC
Untrue. JavaScript's Array.prototype.length is a constant property that's updated on array mutation, not a runtime function.
Comment 12 Giovanni Campagna 2011-12-07 14:15:38 UTC
(In reply to comment #11)
> Untrue. JavaScript's Array.prototype.length is a constant property that's
> updated on array mutation, not a runtime function.

But PopupMenu.numMenuItems is an accessor property that call _getMenuItems(), which is O(N), both in gjs binding code (to convert a GList to an Array) and in JS (to filter stuff that's not a PopupBaseMenuItem).
Comment 13 Jasper St. Pierre (not reading bugmail) 2011-12-07 14:22:43 UTC
Review of attachment 201709 [details] [review]:

OK, sure. I still think we'd need to clean the network code up more in general, later.
Comment 14 Giovanni Campagna 2011-12-07 14:35:38 UTC
Comment on attachment 201709 [details] [review]
NetworkMenu: fix number of visible networks

Attachment 201709 [details] pushed as aad9179 - NetworkMenu: fix number of visible networks
Comment 15 Giovanni Campagna 2011-12-09 11:19:40 UTC
*** Bug 665838 has been marked as a duplicate of this bug. ***
Comment 16 Jasper St. Pierre (not reading bugmail) 2011-12-16 07:34:08 UTC
Review of attachment 201708 [details] [review]:

Yes.
Comment 17 Giovanni Campagna 2011-12-16 07:58:38 UTC
Attachment 201708 [details] pushed as f3cb9d0 - Network Menu: update the UI only when really needed