Blame SOURCES/0001-environment-reduce-calls-to-g_time_zone_new_local.patch

547cbf
From dd03c3a2fe0c87dc1823aad578f95e972aba50a9 Mon Sep 17 00:00:00 2001
547cbf
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
547cbf
Date: Thu, 27 Feb 2020 13:46:44 -0800
547cbf
Subject: [PATCH 1/6] environment: reduce calls to g_time_zone_new_local()
547cbf
547cbf
Creating a new GTimeZone for the local timezone can be quite expensive if
547cbf
done repeatedly. It requires an open(), mmap(), and parsing of
547cbf
/etc/localtime.
547cbf
547cbf
This patch was provided by Florian, and I've tested it as far back as
547cbf
3.28.4 to ensure that we are really reducing the number of open() calls
547cbf
on the compositor thread.
547cbf
547cbf
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/1051
547cbf
547cbf
Signed-off-by: Christian Hergert <chergert@redhat.com>
547cbf
---
547cbf
 js/ui/environment.js | 22 +++++++++++++++++++++-
547cbf
 1 file changed, 21 insertions(+), 1 deletion(-)
547cbf
547cbf
diff --git a/js/ui/environment.js b/js/ui/environment.js
547cbf
index 719680f61..78a24f888 100644
547cbf
--- a/js/ui/environment.js
547cbf
+++ b/js/ui/environment.js
547cbf
@@ -17,6 +17,9 @@ const Gtk = imports.gi.Gtk;
547cbf
 const Lang = imports.lang;
547cbf
 const Shell = imports.gi.Shell;
547cbf
 const St = imports.gi.St;
547cbf
+const System = imports.system;
547cbf
+
547cbf
+let _localTimeZone = null;
547cbf
 
547cbf
 // We can't import shell JS modules yet, because they may have
547cbf
 // variable initializations, etc, that depend on init() already having
547cbf
@@ -116,9 +119,26 @@ function init() {
547cbf
         }
547cbf
     };
547cbf
 
547cbf
+    // Override to clear our own timezone cache as well
547cbf
+    const origClearDateCaches = System.clearDateCaches;
547cbf
+    System.clearDateCaches = function () {
547cbf
+        _localTimeZone = null;
547cbf
+        origClearDateCaches();
547cbf
+    };
547cbf
+
547cbf
     // Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783
547cbf
     Date.prototype.toLocaleFormat = function(format) {
547cbf
-        return Shell.util_format_date(format, this.getTime());
547cbf
+        if (_localTimeZone === null)
547cbf
+            _localTimeZone = GLib.TimeZone.new_local();
547cbf
+
547cbf
+        let dt = GLib.DateTime.new(_localTimeZone,
547cbf
+            this.getYear(),
547cbf
+            this.getMonth() + 1,
547cbf
+            this.getDate(),
547cbf
+            this.getHours(),
547cbf
+            this.getMinutes(),
547cbf
+            this.getSeconds());
547cbf
+        return dt ? dt.format(format) : '';
547cbf
     };
547cbf
 
547cbf
     let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
547cbf
-- 
547cbf
2.26.0
547cbf