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 416094 - Excessive GSList allocation in g_main_context_dispatch
Excessive GSList allocation in g_main_context_dispatch
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: mainloop
2.12.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2007-03-08 15:30 UTC by Chris Wilson
Modified: 2007-03-15 08:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Allocate the GSList link on the stack. (942 bytes, patch)
2007-03-08 15:39 UTC, Chris Wilson
none Details | Review
Allocate the link on the stack and eliminate the call to g_slist_remove_link() (942 bytes, patch)
2007-03-08 15:43 UTC, Chris Wilson
none Details | Review
84250: Allocate the link on the stack and eliminate the call to g_slist_remove_link() (934 bytes, patch)
2007-03-08 15:45 UTC, Chris Wilson
reviewed Details | Review
Use a link on the stack, and add a comment justifying why it's safe to do so (1.31 KB, patch)
2007-03-09 09:14 UTC, Chris Wilson
none Details | Review
Use a link on the stack, and add a comment justifying why it's safe to do so (1.38 KB, patch)
2007-03-14 09:41 UTC, Chris Wilson
accepted-commit_now Details | Review

Description Chris Wilson 2007-03-08 15:30:53 UTC
Surprisingly one of the most frequent allocators whilst running vte/g-t is the g_slist_prepend() in g_main_context_dispatch. Here we can simply allocate the node on the stack.
Comment 1 Chris Wilson 2007-03-08 15:39:06 UTC
Created attachment 84249 [details] [review]
Allocate the GSList link on the stack.
Comment 2 Chris Wilson 2007-03-08 15:43:50 UTC
Created attachment 84250 [details] [review]
Allocate the link on the stack and eliminate the call to g_slist_remove_link()

Whilst we are modifying the current->source, we could also insert the sanity check that the local link is the list head and eliminate the call to g_slist_remove_link.
Comment 3 Chris Wilson 2007-03-08 15:45:01 UTC
Created attachment 84251 [details] [review]
84250: Allocate the link on the stack and eliminate the call to g_slist_remove_link()

[Forget to refresh the patch before sending. ]:
Comment 4 Matthias Clasen 2007-03-09 03:29:45 UTC
Looks ok to me; it should probably have a comment. 
Comment 5 Chris Wilson 2007-03-09 09:14:11 UTC
Created attachment 84298 [details] [review]
Use a link on the stack, and add a comment justifying why it's safe to do so
Comment 6 Xan Lopez 2007-03-14 07:09:45 UTC
Incredibly small nitpick: adding a comment that refers to code that is not there anymore seems a bit confusing to me. If we really want a comment here I think it should explicitly tell how this was done before or just explain the problem in abstract terms. Reading this code feels a bit like:

/* No need to use stupid_and_slow_division_by_2 () */
a = a >> 1;
Comment 7 Chris Wilson 2007-03-14 09:41:45 UTC
Created attachment 84562 [details] [review]
Use a link on the stack, and add a comment justifying why it's safe to do so

Okay, Xan I take your point; but AIUI the comment needs to show that the complications of scope have been taken into account and justify why one shouldn't just use the more conventional and more readible g_slist_prepend()/g_slist_remove(). I see it as a plea:
/* This is a performance hack - do not revert to g_slist_prepend! */

* considers using that as the comment instead...
Comment 8 Matthias Clasen 2007-03-15 03:22:36 UTC
looks good to commit
Comment 9 Chris Wilson 2007-03-15 08:52:04 UTC
Committed to trunk: r5407

2007-03-15  Chris Wilson  <chris@chris-wilson.co.uk>

	* glib/gmain.c (g_main_dispatch): Replace a
	g_slist_prepend/g_slist_remove pair with an on-stack link
	and open coding. (#416094)