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 659254 - reduce number of calls to malloc to mitigate fragmentation
reduce number of calls to malloc to mitigate fragmentation
Status: RESOLVED OBSOLETE
Product: gnome-shell
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gnome-shell-maint
gnome-shell-maint
Depends on: 659253
Blocks:
 
 
Reported: 2011-09-16 14:44 UTC by Colin Walters
Modified: 2021-07-05 14:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
memory: Add display of elapsed seconds since a garbage collection (3.90 KB, patch)
2011-09-16 14:44 UTC, Colin Walters
committed Details | Review
global: Initiate *full* GC at idle (1.70 KB, patch)
2011-09-16 14:44 UTC, Colin Walters
committed Details | Review
theme: Minor memory usage optimization (3.96 KB, patch)
2011-09-16 14:46 UTC, Colin Walters
reviewed Details | Review

Description Colin Walters 2011-09-16 14:44:26 UTC
See attached.
Comment 1 Colin Walters 2011-09-16 14:44:29 UTC
Created attachment 196731 [details] [review]
memory: Add display of elapsed seconds since a garbage collection

This is useful information for debugging.
Comment 2 Colin Walters 2011-09-16 14:44:32 UTC
Created attachment 196732 [details] [review]
global: Initiate *full* GC at idle

While I've been trying to make the GC kick in more often, I've decided
it's a better tradeoff to aggressively GC at "leisure", for multiple
reasons.

We can and should revisit this at a later time, but basically:

* The shell doesn't generate *that* much JS data - garbage collection
  is very fast here.
* Long periods without GC mean we're not calling free() when we
  could, which in turn makes heap fragmentation much worse.
* Ensuring the GC runs at idle makes it much less likely we'll take
  a random large GC hit in the middle of an animation.
Comment 3 Colin Walters 2011-09-16 14:46:45 UTC
Created attachment 196733 [details] [review]
theme: Minor memory usage optimization

While profiling with Massif, about 2% of our allocated space is in
over 1000 calls to g_strdup().  Because there are many StThemeNode
instances allocated, we can reduce the calls to malloc() here.
Comment 4 Colin Walters 2011-09-16 15:01:15 UTC
(In reply to comment #2)
> Created an attachment (id=196732) [details] [review]
> global: Initiate *full* GC at idle

I'd definitely like people to test this and report any performance regressions.  By regression here I basically mean, does it "feel" slower for you?  

We don't currently have any perf metrics for this.
Comment 5 Matthias Clasen 2011-09-16 17:34:06 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > Created an attachment (id=196732) [details] [review] [details] [review]
> > global: Initiate *full* GC at idle
> 
> I'd definitely like people to test this and report any performance regressions.
>  By regression here I basically mean, does it "feel" slower for you?  
> 
> We don't currently have any perf metrics for this.

Which probably means that it is not suitable for 3.1 at this point, right ?
Comment 6 Colin Walters 2011-09-16 18:01:57 UTC
(In reply to comment #5)
> 
> Which probably means that it is not suitable for 3.1 at this point, right ?

I think we should really consider it.  I'd very much like people to try these patches and see.
Comment 7 Colin Walters 2011-09-16 19:36:42 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > We don't currently have any perf metrics for this.
> 
> Which probably means that it is not suitable for 3.1 at this point, right ?

Oh and if you mean "do we know if this is worth it?" -  I can say it makes the RSS grow noticeably more slowly on my system.
Comment 8 drago01 2011-09-16 19:53:40 UTC
Review of attachment 196731 [details] [review]:

Makes sense and looks good to me.
Comment 9 drago01 2011-09-16 19:55:42 UTC
Review of attachment 196732 [details] [review]:

From quick testing it does not seem to cause any noticeable slowdown, but I have not run it for long enough to be sure about that.
Code looks fine .. do we still want to keep shell_global_maybe_gc() around? (will be unused after this patch).
Comment 10 Colin Walters 2011-09-17 14:22:47 UTC
(In reply to comment #9)
> Review of attachment 196732 [details] [review]:
> 
> From quick testing it does not seem to cause any noticeable slowdown, but I
> have not run it for long enough to be sure about that.
> Code looks fine .. do we still want to keep shell_global_maybe_gc() around?
> (will be unused after this patch).

Yeah, you can still run it from looking glass I guess.

(We have a lot of API duplication and wrapping because the gjs API isn't introspectable, and neither is the Spidermonkey one).
Comment 11 Colin Walters 2011-09-17 14:23:04 UTC
Attachment 196731 [details] pushed as 36bfe8c - memory: Add display of elapsed seconds since a garbage collection
Attachment 196732 [details] pushed as f54b82f - global: Initiate *full* GC at idle
Comment 12 Colin Walters 2011-09-17 14:24:15 UTC
Leaving this bug open for the theme patch (not critical, can wait for 3.3 to open).
Comment 13 Funda Wang 2011-09-21 00:47:56 UTC
I guess gjs req should be bumped to 1.29.18 in configure.ac
Comment 14 Jasper St. Pierre (not reading bugmail) 2011-09-21 04:51:58 UTC
Review of attachment 196733 [details] [review]:

If this isn't a noticeable speedup, I'm not sure we want this. It's fairly complex, I'd say due to the generic nature and varargs. A simple cleanup would be to make it fixed with four strings.
Comment 15 Colin Walters 2011-09-21 17:45:32 UTC
(In reply to comment #14)
> Review of attachment 196733 [details] [review]:
> 
> If this isn't a noticeable speedup, I'm not sure we want this. It's fairly
> complex, I'd say due to the generic nature and varargs. A simple cleanup would
> be to make it fixed with four strings.

I can't claim this particular fix is large in itself.  But I'm not going to go around micro-optimizing the entire source tree.  What I'm looking for is places where malloc() is called frequently, e.g. inside a loop.  Particularly if these malloc() calls are long-lived and especially if they interleave with short-lived calls.

See: http://blog.pavlov.net/2007/11/10/memory-fragmentation/ for why fragmentation can be a serious problem.

This qualifies as an instance of that.  How much does this one patch help?  From quick instrumentation, I have ~450 theme nodes peak after entering the overview.  That means we save 450*3 or 1350 calls to g_strdup() - not a small number.
Comment 16 Colin Walters 2011-09-21 17:47:23 UTC
(In reply to comment #15)
> (
> This qualifies as an instance of that.  How much does this one patch help? 
> From quick instrumentation, I have ~450 theme nodes peak after entering the
> overview.  That means we save 450*3 or 1350 calls to g_strdup() - not a small
> number.

Actually we allocate ~950 theme nodes, so this really saves 2850 calls to g_strdup() total.
Comment 17 drago01 2013-03-03 22:58:31 UTC
So what are we going to do with this?
Comment 18 Bastien Nocera 2013-04-11 10:25:12 UTC
How many *different* strings do we have here? Would it be possible to use referenced strings (like Rhythmbox does), or use GQuarks (do they get disposed? do they need to get disposed?) ?
Comment 19 GNOME Infrastructure Team 2021-07-05 14:08:02 UTC
GNOME is going to shut down bugzilla.gnome.org in favor of  gitlab.gnome.org.
As part of that, we are mass-closing older open tickets in bugzilla.gnome.org
which have not seen updates for a longer time (resources are unfortunately
quite limited so not every ticket can get handled).

If you can still reproduce the situation described in this ticket in a recent
and supported software version, then please follow
  https://wiki.gnome.org/GettingInTouch/BugReportingGuidelines
and create a new ticket at
  https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/

Thank you for your understanding and your help.