[gnome-shell/wip/chergert/3-28-perf-fixes] shell-util: add API to reduce GTimeZone usage
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/chergert/3-28-perf-fixes] shell-util: add API to reduce GTimeZone usage
- Date: Thu, 27 Feb 2020 08:12:33 +0000 (UTC)
commit 3d4ebb708555a1e9f334d85455d66dd995f4d12f
Author: Christian Hergert <chergert redhat com>
Date: Thu Feb 27 00:11:57 2020 -0800
shell-util: add API to reduce GTimeZone usage
Creating new GTimeZone with g_time_zone_new_local() requires opening
/etc/localtime, mmap()'ing it, and parsing information from it. This is
quite a bit of work to do from the compositor thread for the amount we
do it.
Instead, we can cache that value and provide a simplified form to access
it.
js/ui/dateMenu.js | 3 +++
js/ui/environment.js | 2 +-
src/shell-util.c | 26 ++++++++++++++++++++++++++
src/shell-util.h | 2 ++
4 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index 60f5bdc45f..8066790eb0 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -573,6 +573,9 @@ var DateMenuButton = new Lang.Class({
// https://bugzilla.gnome.org/show_bug.cgi?id=678507
System.clearDateCaches();
+ // shell-utils also caches the current timezone to reduce overhead
+ Shell.util_clear_timezone_cache();
+
this._calendar.updateTimeZone();
},
diff --git a/js/ui/environment.js b/js/ui/environment.js
index 719680f615..a2a15a5991 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -118,7 +118,7 @@ function init() {
// Work around https://bugzilla.mozilla.org/show_bug.cgi?id=508783
Date.prototype.toLocaleFormat = function(format) {
- return Shell.util_format_date(format, this.getTime());
+ return Shell.util_format_now(format);
};
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
diff --git a/src/shell-util.c b/src/shell-util.c
index 70b8c06110..46b81da66b 100644
--- a/src/shell-util.c
+++ b/src/shell-util.c
@@ -20,6 +20,8 @@
#include <langinfo.h>
#endif
+static GTimeZone *local_tz;
+
static void
stop_pick (ClutterActor *actor,
const ClutterColor *color)
@@ -154,6 +156,24 @@ shell_util_format_date (const char *format,
return result;
}
+char *
+shell_util_format_now (const char *format)
+{
+ GDateTime *datetime;
+ char *ret;
+
+ if (local_tz == NULL)
+ local_tz = g_time_zone_new_local ();
+
+ datetime = g_date_time_new_now (local_tz);
+ if (!datetime)
+ return g_strdup ("");
+
+ ret = g_date_time_format (datetime, format);
+ g_date_time_unref (datetime);
+ return ret;
+}
+
/**
* shell_util_get_week_start:
*
@@ -514,3 +534,9 @@ shell_util_composite_capture_images (ClutterCapture *captures,
return image;
}
+
+void
+shell_util_clear_timezone_cache (void)
+{
+ g_clear_pointer (&local_tz, g_time_zone_unref);
+}
diff --git a/src/shell-util.h b/src/shell-util.h
index 2218594c19..8b31c9eb7a 100644
--- a/src/shell-util.h
+++ b/src/shell-util.h
@@ -22,6 +22,8 @@ int shell_util_get_week_start (void);
char *shell_util_format_date (const char *format,
gint64 time_ms);
+char *shell_util_format_now (const char *format);
+void shell_util_clear_timezone_cache (void);
const char *shell_util_translate_time_string (const char *str);
char *shell_util_regex_escape (const char *str);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]