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

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