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

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