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 737445 - optimise GPrivate
optimise GPrivate
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-09-26 15:17 UTC by Allison Karlitskaya (desrt)
Modified: 2018-05-24 17:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GPrivate: change return type of internal function (2.18 KB, patch)
2014-09-26 15:17 UTC, Allison Karlitskaya (desrt)
none Details | Review
GPrivate: a nice optimisation (3.72 KB, patch)
2014-09-26 15:17 UTC, Allison Karlitskaya (desrt)
reviewed Details | Review

Description Allison Karlitskaya (desrt) 2014-09-26 15:17:02 UTC
We could avoid an extra malloc() in the implementation of GPrivate on
Linux.  Here's some patches for that.

It may also be possible to implement GPrivate more efficiently for
ourselves, but that is a story for later...

Note that the memcpy() calls in these patches are required to avoid
breaking strict aliasing rules.  Since the operation is being performed
with a small constant size, it is optimised out by the compiler and
replaced with a simple assignment.
Comment 1 Allison Karlitskaya (desrt) 2014-09-26 15:17:04 UTC
Created attachment 287174 [details] [review]
GPrivate: change return type of internal function

g_private_get_impl() was returning a pointer to the pthread_key_t, but every
function using this was immediately dereferencing it.  Change it so that we
dereference the value in the helper function and return it by value.
Comment 2 Allison Karlitskaya (desrt) 2014-09-26 15:17:10 UTC
Created attachment 287175 [details] [review]
GPrivate: a nice optimisation

We don't know how big a pthread_key_t is, so we malloc() a big enough
chunk of memory for it and store a pointer into the GPrivate struct.

It turns out, on Linux, pthread_key_t is just an int, so we could much
easier just store it directly into the struct.
Comment 3 Matthias Clasen 2014-09-26 17:21:00 UTC
Review of attachment 287175 [details] [review]:

::: glib/gthread-posix.c
@@ +1056,3 @@
+
+          if G_UNLIKELY (impl == NULL)
+            g_thread_abort (status, "pthread_key_create (gave non-NULL result twice)");

s/non-NULL/NULL/ here ?
Comment 4 GNOME Infrastructure Team 2018-05-24 17:03:16 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/931.