[gjs: 7/9] arg-cache: Save GType information for RegisteredType




commit 3eae94110e3bdc94867cd82cdeb9e90e721c5504
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Oct 27 13:41:23 2020 +0100

    arg-cache: Save GType information for RegisteredType
    
    This is a reimplementation of commit d526bf8, but re-applied on top of
    this branch, to make it clearer. The rationale stays:
    
    As found in https://gitlab.gnome.org/GNOME/gjs/-/issues/361, getting the
    GType using g_registered_type_info_get_g_type() is very expensive and
    can make up for a significant part of the overhead when calling into a C
    function.
    
    Since the argument cache seems to be fairly small in a typical
    gnome-shell session (about 1300 entries), the total increased memory
    usage of about 10kB seems very reasonable given the benefits of the
    caching.

 gi/arg-cache.cpp | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/gi/arg-cache.cpp b/gi/arg-cache.cpp
index e85a260b..5b77e4ff 100644
--- a/gi/arg-cache.cpp
+++ b/gi/arg-cache.cpp
@@ -216,19 +216,26 @@ struct Array : BasicType {
     }
 };
 
-// boxed / union / GObject
-struct RegisteredType {
-    explicit RegisteredType(GIRegisteredTypeInfo* info)
+struct BaseInfo {
+    explicit BaseInfo(GIBaseInfo* info)
         : m_info(info ? g_base_info_ref(info) : nullptr) {}
 
-    GType gtype() const { return g_registered_type_info_get_g_type(m_info); }
-
     GjsAutoBaseInfo m_info;
 };
 
-struct Callback : Nullable, RegisteredType {
+// boxed / union / GObject
+struct RegisteredType : BaseInfo {
+    explicit RegisteredType(GIBaseInfo* info)
+        : BaseInfo(info), m_gtype(g_registered_type_info_get_g_type(m_info)) {}
+
+    constexpr GType gtype() const { return m_gtype; }
+
+    GType m_gtype;
+};
+
+struct Callback : Nullable, BaseInfo {
     explicit Callback(GITypeInfo* type_info)
-        : RegisteredType(g_type_info_get_interface(type_info)),
+        : BaseInfo(g_type_info_get_interface(type_info)),
           m_scope(GI_SCOPE_TYPE_INVALID) {}
 
     inline void set_callback_destroy_pos(int pos) {
@@ -1455,7 +1462,7 @@ constexpr size_t argument_maximum_size() {
                   std::is_same_v<T, Arg::BoxedIn>)
         return 48;
     else
-        return 112;
+        return 120;
 }
 #endif
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]