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
1=== modified file 'dee/dee-sequence-model.c'
2--- dee/dee-sequence-model.c 2011-10-21 10:37:03 +0000
3+++ dee/dee-sequence-model.c 2011-12-09 14:18:23 +0000
4@@ -56,6 +56,11 @@
5 #define DEE_SEQUENCE_MODEL_GET_PRIVATE(obj) \
6 (G_TYPE_INSTANCE_GET_PRIVATE(obj, DEE_TYPE_SEQUENCE_MODEL, DeeSequenceModelPrivate))
7
8+/* Signal ids for emitting row update signals a just a smidgeon faster */
9+static guint sigid_row_added;
10+static guint sigid_row_removed;
11+static guint sigid_row_changed;
12+
13 /**
14 * DeeSequenceModelPrivate:
15 *
16@@ -227,6 +232,11 @@
17 obj_class->set_property = dee_sequence_model_set_property;
18 obj_class->get_property = dee_sequence_model_get_property;
19
20+ /* Find signal ids for the model modification signals */
21+ sigid_row_added = g_signal_lookup ("row-added", DEE_TYPE_SEQUENCE_MODEL);
22+ sigid_row_removed = g_signal_lookup ("row-removed", DEE_TYPE_SEQUENCE_MODEL);
23+ sigid_row_changed = g_signal_lookup ("row-changed", DEE_TYPE_SEQUENCE_MODEL);
24+
25 /* Add private data */
26 g_type_class_add_private (obj_class, sizeof (DeeSequenceModelPrivate));
27 }
28@@ -304,7 +314,7 @@
29 priv->setting_many = FALSE;
30
31 dee_serializable_model_inc_seqnum (self);
32- g_signal_emit_by_name (self, "row-added", iter);
33+ g_signal_emit (self, sigid_row_added, 0, iter);
34
35 return iter;
36 }
37@@ -330,7 +340,7 @@
38 priv->setting_many = FALSE;
39
40 dee_serializable_model_inc_seqnum (self);
41- g_signal_emit_by_name (self, "row-added", iter);
42+ g_signal_emit (self, sigid_row_added, 0, iter);
43
44 return iter;
45 }
46@@ -357,7 +367,7 @@
47 priv->setting_many = FALSE;
48
49 dee_serializable_model_inc_seqnum (self);
50- g_signal_emit_by_name (self, "row-added", iter);
51+ g_signal_emit (self, sigid_row_added, 0, iter);
52
53 return iter;
54 }
55@@ -380,7 +390,7 @@
56 /* Emit the removed signal while the iter is still valid,
57 * but after we increased the seqnum */
58 dee_serializable_model_inc_seqnum (self);
59- g_signal_emit_by_name (self, "row-removed", iter_);
60+ g_signal_emit (self, sigid_row_removed, 0, iter_);
61 dee_sequence_model_free_row (_self, iter);
62 g_sequence_remove (iter);
63 }
64@@ -410,7 +420,7 @@
65 if (priv->setting_many == FALSE)
66 {
67 dee_serializable_model_inc_seqnum (self);
68- g_signal_emit_by_name (self, "row-changed", iter);
69+ g_signal_emit (self, sigid_row_changed, 0, iter);
70 }
71 }
72
73@@ -438,7 +448,7 @@
74 if (priv->setting_many == FALSE)
75 {
76 dee_serializable_model_inc_seqnum (self);
77- g_signal_emit_by_name (self, "row-changed", iter);
78+ g_signal_emit (self, sigid_row_changed, 0, iter);
79 }
80 }
81
82
83=== modified file 'tests/test-benchmark.c'
84--- tests/test-benchmark.c 2011-12-07 15:45:47 +0000
85+++ tests/test-benchmark.c 2011-12-09 14:18:23 +0000
86@@ -128,7 +128,7 @@
87 bench_seqmodel_append_run (Benchmark *bench)
88 {
89 DeeModel *model;
90- guint limit = 1000, i;
91+ guint limit = 2500, i;
92
93 g_assert (DEE_IS_MODEL (bench->state));
94
95@@ -144,7 +144,7 @@
96 bench_seqmodel_prepend_run (Benchmark *bench)
97 {
98 DeeModel *model;
99- guint limit = 1000, i;
100+ guint limit = 2500, i;
101
102 g_assert (DEE_IS_MODEL (bench->state));
103
104@@ -175,7 +175,7 @@
105 bench_seqmodel_setup,
106 bench_seqmodel_append_run,
107 bench_gobject_teardown,
108- 10,
109+ 100,
110 NULL };
111 add_benchmark (&seqmodel_append);
112
113@@ -183,7 +183,7 @@
114 bench_seqmodel_setup,
115 bench_seqmodel_prepend_run,
116 bench_gobject_teardown,
117- 10,
118+ 100,
119 NULL };
120 add_benchmark (&seqmodel_prepend);
121

Subscribers

People subscribed via source and target branches