dee

Merge lp:~kamstrup/dee/signal-by-id into lp:dee

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Approved by: Michal Hruby
Approved revision: 321
Merged at revision: 318
Proposed branch: lp:~kamstrup/dee/signal-by-id
Merge into: lp:dee
Diff against target: 120 lines (+20/-10)
2 files modified
dee/dee-sequence-model.c (+16/-6)
tests/test-benchmark.c (+4/-4)
To merge this branch: bzr merge lp:~kamstrup/dee/signal-by-id
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+84821@code.launchpad.net

Description of the change

Emit signal by id, not by name, in DeeSequenceModel for a small perf gain

The benchmark suite indicates a 0 > x > 1% perf gain from this - but non-zero!
I expect the numbers to be slightly better on lower end hardware, and also when
looking on the actual spend CPU time, which I haven't done.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

I'd prefer if we just used static ints initialized during class_init (or perhaps instance init if it's not available during class_init). There's no need to add these to each and every instance.

review: Needs Fixing
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Totally agreed, that was a pretty braindead way of doing this :-)

Pushed r321 with the requested changes. Please re-review.

lp:~kamstrup/dee/signal-by-id updated
321. By Mikkel Kamstrup Erlandsen

Move signal ids for row-{added,changed,removed} into global static variables instead of instance members

Revision history for this message
Michal Hruby (mhr3) wrote :

> Totally agreed, that was a pretty braindead way of doing this :-)

I think that you actually thought about it quite a lot the first time ;) Doing g_signal_lookup during class_init of the type you're looking up does sound very racy, I'm actually surprised that it works.

The question is if we're going to assume that will continue working / move it to instance_init (with a GOnce guard) / or just use what was in r320.

review: Needs Information
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

I'd assume we could use it in class_init() just fine.

It rests on the assumption that GObject works like this: When
instantiating a DeeSequenceModel for the first time glib first looks
up all the GTypes involved to figure out the hierarchy. Then it call
class_init()s from the top of the inheritance tree (imagine a memcpy()
on the class struct in between each step) like GObject.class_init(),
DeeModel.iface_init(), DeeSerializableModel.class_init(), and lastly
DeeSequenceModel.class_init().

If the parent class/ifaces are not fully initialized when entering
class_init() of the children all sorts of things would go b0rkedI
believe.

Revision history for this message
Michal Hruby (mhr3) wrote :

Very well then, let's assume a little. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dee/dee-sequence-model.c'
--- dee/dee-sequence-model.c 2011-10-21 10:37:03 +0000
+++ dee/dee-sequence-model.c 2011-12-09 14:18:23 +0000
@@ -56,6 +56,11 @@
56#define DEE_SEQUENCE_MODEL_GET_PRIVATE(obj) \56#define DEE_SEQUENCE_MODEL_GET_PRIVATE(obj) \
57 (G_TYPE_INSTANCE_GET_PRIVATE(obj, DEE_TYPE_SEQUENCE_MODEL, DeeSequenceModelPrivate))57 (G_TYPE_INSTANCE_GET_PRIVATE(obj, DEE_TYPE_SEQUENCE_MODEL, DeeSequenceModelPrivate))
5858
59/* Signal ids for emitting row update signals a just a smidgeon faster */
60static guint sigid_row_added;
61static guint sigid_row_removed;
62static guint sigid_row_changed;
63
59/**64/**
60 * DeeSequenceModelPrivate:65 * DeeSequenceModelPrivate:
61 *66 *
@@ -227,6 +232,11 @@
227 obj_class->set_property = dee_sequence_model_set_property;232 obj_class->set_property = dee_sequence_model_set_property;
228 obj_class->get_property = dee_sequence_model_get_property;233 obj_class->get_property = dee_sequence_model_get_property;
229234
235 /* Find signal ids for the model modification signals */
236 sigid_row_added = g_signal_lookup ("row-added", DEE_TYPE_SEQUENCE_MODEL);
237 sigid_row_removed = g_signal_lookup ("row-removed", DEE_TYPE_SEQUENCE_MODEL);
238 sigid_row_changed = g_signal_lookup ("row-changed", DEE_TYPE_SEQUENCE_MODEL);
239
230 /* Add private data */240 /* Add private data */
231 g_type_class_add_private (obj_class, sizeof (DeeSequenceModelPrivate));241 g_type_class_add_private (obj_class, sizeof (DeeSequenceModelPrivate));
232}242}
@@ -304,7 +314,7 @@
304 priv->setting_many = FALSE;314 priv->setting_many = FALSE;
305315
306 dee_serializable_model_inc_seqnum (self);316 dee_serializable_model_inc_seqnum (self);
307 g_signal_emit_by_name (self, "row-added", iter);317 g_signal_emit (self, sigid_row_added, 0, iter);
308 318
309 return iter;319 return iter;
310}320}
@@ -330,7 +340,7 @@
330 priv->setting_many = FALSE;340 priv->setting_many = FALSE;
331341
332 dee_serializable_model_inc_seqnum (self);342 dee_serializable_model_inc_seqnum (self);
333 g_signal_emit_by_name (self, "row-added", iter);343 g_signal_emit (self, sigid_row_added, 0, iter);
334 344
335 return iter;345 return iter;
336}346}
@@ -357,7 +367,7 @@
357 priv->setting_many = FALSE;367 priv->setting_many = FALSE;
358368
359 dee_serializable_model_inc_seqnum (self);369 dee_serializable_model_inc_seqnum (self);
360 g_signal_emit_by_name (self, "row-added", iter);370 g_signal_emit (self, sigid_row_added, 0, iter);
361 371
362 return iter;372 return iter;
363}373}
@@ -380,7 +390,7 @@
380 /* Emit the removed signal while the iter is still valid,390 /* Emit the removed signal while the iter is still valid,
381 * but after we increased the seqnum */391 * but after we increased the seqnum */
382 dee_serializable_model_inc_seqnum (self);392 dee_serializable_model_inc_seqnum (self);
383 g_signal_emit_by_name (self, "row-removed", iter_);393 g_signal_emit (self, sigid_row_removed, 0, iter_);
384 dee_sequence_model_free_row (_self, iter);394 dee_sequence_model_free_row (_self, iter);
385 g_sequence_remove (iter);395 g_sequence_remove (iter);
386 }396 }
@@ -410,7 +420,7 @@
410 if (priv->setting_many == FALSE)420 if (priv->setting_many == FALSE)
411 {421 {
412 dee_serializable_model_inc_seqnum (self);422 dee_serializable_model_inc_seqnum (self);
413 g_signal_emit_by_name (self, "row-changed", iter);423 g_signal_emit (self, sigid_row_changed, 0, iter);
414 }424 }
415}425}
416426
@@ -438,7 +448,7 @@
438 if (priv->setting_many == FALSE)448 if (priv->setting_many == FALSE)
439 {449 {
440 dee_serializable_model_inc_seqnum (self);450 dee_serializable_model_inc_seqnum (self);
441 g_signal_emit_by_name (self, "row-changed", iter);451 g_signal_emit (self, sigid_row_changed, 0, iter);
442 }452 }
443}453}
444454
445455
=== modified file 'tests/test-benchmark.c'
--- tests/test-benchmark.c 2011-12-07 15:45:47 +0000
+++ tests/test-benchmark.c 2011-12-09 14:18:23 +0000
@@ -128,7 +128,7 @@
128bench_seqmodel_append_run (Benchmark *bench)128bench_seqmodel_append_run (Benchmark *bench)
129{129{
130 DeeModel *model;130 DeeModel *model;
131 guint limit = 1000, i;131 guint limit = 2500, i;
132 132
133 g_assert (DEE_IS_MODEL (bench->state));133 g_assert (DEE_IS_MODEL (bench->state));
134 134
@@ -144,7 +144,7 @@
144bench_seqmodel_prepend_run (Benchmark *bench)144bench_seqmodel_prepend_run (Benchmark *bench)
145{145{
146 DeeModel *model;146 DeeModel *model;
147 guint limit = 1000, i;147 guint limit = 2500, i;
148 148
149 g_assert (DEE_IS_MODEL (bench->state));149 g_assert (DEE_IS_MODEL (bench->state));
150 150
@@ -175,7 +175,7 @@
175 bench_seqmodel_setup,175 bench_seqmodel_setup,
176 bench_seqmodel_append_run,176 bench_seqmodel_append_run,
177 bench_gobject_teardown,177 bench_gobject_teardown,
178 10,178 100,
179 NULL };179 NULL };
180 add_benchmark (&seqmodel_append);180 add_benchmark (&seqmodel_append);
181 181
@@ -183,7 +183,7 @@
183 bench_seqmodel_setup,183 bench_seqmodel_setup,
184 bench_seqmodel_prepend_run,184 bench_seqmodel_prepend_run,
185 bench_gobject_teardown,185 bench_gobject_teardown,
186 10,186 100,
187 NULL };187 NULL };
188 add_benchmark (&seqmodel_prepend);188 add_benchmark (&seqmodel_prepend);
189189

Subscribers

People subscribed via source and target branches