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

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