mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 22:46:15 +01:00
d8e4f39aa8
GSList doesn't seem the best choice here. It's benefits are that it's relatively convenient to use (albeit not very efficient) and that an empty list requires only the pointer to the list's head. But for non-empty list, we need to allocate GSList elements. We can do better, by writing more code. I think it's worth optimizing GObject, at the expense of a bit(?) more complicated code. The complicated code is still entirely self-contained, so unless you review WeakRefData usage, it doesn't need to bother you. Note that this can be easily measure to be a bit faster. But I think the more important part is to safe some allocations. Often objects are long-lived, and the GWeakRef will be tracked for a long time. It is interesting, to optimize the memory usage of that. - if the list only contains one weak reference, it's interned/embedded in WeakRefData.list.one. Otherwise, an array is allocated and tracked at WeakRefData.list.many. - when the buffer grows, we double the size. When the buffer shrinks, we reallocate to 50% when 75% are empty. When the buffer shrinks to length 1, we free it (so that "list.one" is always used with a length of 1). That means, at worst case we waste 75% of the allocated buffer, which is a choice in the hope that future weak references will be registered, and that this is a suitable strategy. - on architectures like x86_68, does this not increase the size of WeakRefData. Also, the number of weak-refs is now limited to 65535, and now an assertion fails when you try to register more than that. But note that the internal tracking just uses a linear search, so you really don't want to register thousands of weak references on an object. If you do that, the current implementation is not suitable anyway and you must rethink your approach. Nor does it make sense to optimize the implementation for such a use case. Instead, the implementation is optimized for a few (one!) weak reference per object. |
||
---|---|---|
.. | ||
performance | ||
accumulator.c | ||
autoptr.c | ||
basic-signals.c | ||
basics-gobject.c | ||
binding.c | ||
bindinggroup.c | ||
boxed.c | ||
closure-refcount.c | ||
closure.c | ||
custom-dispatch.c | ||
cxx.cpp | ||
defaultiface.c | ||
deftype.c | ||
deprecated-properties.c | ||
dynamictests.c | ||
dynamictype.c | ||
enums.c | ||
flags.c | ||
genmarshal.py | ||
gobject-query.py | ||
ifaceproperties.c | ||
marshalers.list | ||
max-version.c | ||
meson.build | ||
mkenums.py | ||
notify-init2.c | ||
notify-init.c | ||
object.c | ||
objects-refcount1.c | ||
objects-refcount2.c | ||
override.c | ||
param.c | ||
private.c | ||
properties-introspection.c | ||
properties-refcount1.c | ||
properties-refcount2.c | ||
properties-refcount3.c | ||
properties-refcount4.c | ||
properties.c | ||
qdata.c | ||
reference.c | ||
references.c | ||
signal-handler.c | ||
signalgroup.c | ||
signals-refcount.c | ||
signals.c | ||
singleton.c | ||
taptestrunner.py | ||
testcommon.h | ||
testing.c | ||
testmodule.c | ||
testmodule.h | ||
threadtests.c | ||
type-flags.c | ||
type.c | ||
value.c |