From 2b1a7e30b1a2847bd9a8c806c9710c960097dd97 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 6 Mar 2024 12:17:08 +0100 Subject: [PATCH] tests/performance: avoid check for toggle notification in "property-{get,set}" Bumping the reference count from 1 to 2 (and back) is more expensive, due to the check for toggle notifications. We have a performance test already that hits that code path. Avoid that for he "property-{get,set}" tests, so we avoid the known overhead and test more relevant parts. --- gobject/tests/performance/performance.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gobject/tests/performance/performance.c b/gobject/tests/performance/performance.c index e6f09fc86..69a0f14d3 100644 --- a/gobject/tests/performance/performance.c +++ b/gobject/tests/performance/performance.c @@ -1139,6 +1139,12 @@ test_set_setup (PerformanceTest *test) data = g_new0 (struct SetTest, 1); data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + /* g_object_get() will take a reference. Increasing the ref count from 1 to 2 + * is more expensive, due to the check for toggle notifications. We have a + * performance test for that already. Don't also test that overhead during + * "property-get" test and avoid this by taking an additional reference. */ + g_object_ref (data->object); + return data; } @@ -1175,6 +1181,7 @@ test_set_teardown (PerformanceTest *test, { struct SetTest *data = _data; + g_object_unref (data->object); g_object_unref (data->object); g_free (data); } @@ -1210,6 +1217,12 @@ test_get_setup (PerformanceTest *test) data = g_new0 (struct GetTest, 1); data->object = g_object_new (COMPLEX_TYPE_OBJECT, NULL); + /* g_object_get() will take a reference. Increasing the ref count from 1 to 2 + * is more expensive, due to the check for toggle notifications. We have a + * performance test for that already. Don't also test that overhead during + * "property-get" test and avoid this by taking an additional reference. */ + g_object_ref (data->object); + return data; } @@ -1246,6 +1259,7 @@ test_get_teardown (PerformanceTest *test, { struct GetTest *data = _data; + g_object_unref (data->object); g_object_unref (data->object); g_free (data); }