From b66db11c770db8f241feb2511ff5ddf1d043fb18 Mon Sep 17 00:00:00 2001 From: Ignacio Casal Quinteiro Date: Tue, 10 Sep 2024 10:44:45 +0200 Subject: [PATCH] glib: add patch to improve gsocket performance https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4261 --- ...check-event-before-calling-WSAEnumNe.patch | 37 +++++++++++++++++++ ...check-event-before-calling-WSAEnumNe.patch | 37 +++++++++++++++++++ gvsbuild/projects/glib.py | 2 + 3 files changed, 76 insertions(+) create mode 100644 gvsbuild/patches/glib-base/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch create mode 100644 gvsbuild/patches/glib/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch diff --git a/gvsbuild/patches/glib-base/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch b/gvsbuild/patches/glib-base/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch new file mode 100644 index 000000000..6594ff145 --- /dev/null +++ b/gvsbuild/patches/glib-base/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch @@ -0,0 +1,37 @@ +From cfdb60d11d353b2dce440edd54cfaac84f7356ab Mon Sep 17 00:00:00 2001 +From: Silvio Lazzeretti +Date: Thu, 22 Aug 2024 09:16:34 +0200 +Subject: [PATCH] gsocket windows: check event before calling + WSAEnumNetworkEvents + +The WSAEnumNetworkEvents API is called every time the socket +needs to be checked for status changes. Doing this in an application +with several sockets could generate a high cpu usage since +this call is done for each socket at each iteration of the main loop. +Since there is also a WSAEvent that gets signaled when there is +a change in the status of the socket, checking its status and +calling the WSAEnumNetworkEvents API only if the event is signaled, +can reduce the overall cpu usage. +--- + gio/gsocket.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/gio/gsocket.c b/gio/gsocket.c +index ccb5958f7..c36ca62f4 100644 +--- a/gio/gsocket.c ++++ b/gio/gsocket.c +@@ -4107,9 +4107,8 @@ update_condition_unlocked (GSocket *socket) + GIOCondition condition; + + if (!socket->priv->closed && +- WSAEnumNetworkEvents (socket->priv->fd, +- socket->priv->event, +- &events) == 0) ++ (WSAWaitForMultipleEvents (1, &socket->priv->event, FALSE, 0, FALSE) == WSA_WAIT_EVENT_0) && ++ (WSAEnumNetworkEvents (socket->priv->fd, socket->priv->event, &events) == 0)) + { + socket->priv->current_events |= events.lNetworkEvents; + if (events.lNetworkEvents & FD_WRITE && +-- +2.40.0.windows.1 + diff --git a/gvsbuild/patches/glib/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch b/gvsbuild/patches/glib/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch new file mode 100644 index 000000000..6594ff145 --- /dev/null +++ b/gvsbuild/patches/glib/0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch @@ -0,0 +1,37 @@ +From cfdb60d11d353b2dce440edd54cfaac84f7356ab Mon Sep 17 00:00:00 2001 +From: Silvio Lazzeretti +Date: Thu, 22 Aug 2024 09:16:34 +0200 +Subject: [PATCH] gsocket windows: check event before calling + WSAEnumNetworkEvents + +The WSAEnumNetworkEvents API is called every time the socket +needs to be checked for status changes. Doing this in an application +with several sockets could generate a high cpu usage since +this call is done for each socket at each iteration of the main loop. +Since there is also a WSAEvent that gets signaled when there is +a change in the status of the socket, checking its status and +calling the WSAEnumNetworkEvents API only if the event is signaled, +can reduce the overall cpu usage. +--- + gio/gsocket.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +diff --git a/gio/gsocket.c b/gio/gsocket.c +index ccb5958f7..c36ca62f4 100644 +--- a/gio/gsocket.c ++++ b/gio/gsocket.c +@@ -4107,9 +4107,8 @@ update_condition_unlocked (GSocket *socket) + GIOCondition condition; + + if (!socket->priv->closed && +- WSAEnumNetworkEvents (socket->priv->fd, +- socket->priv->event, +- &events) == 0) ++ (WSAWaitForMultipleEvents (1, &socket->priv->event, FALSE, 0, FALSE) == WSA_WAIT_EVENT_0) && ++ (WSAEnumNetworkEvents (socket->priv->fd, socket->priv->event, &events) == 0)) + { + socket->priv->current_events |= events.lNetworkEvents; + if (events.lNetworkEvents & FD_WRITE && +-- +2.40.0.windows.1 + diff --git a/gvsbuild/projects/glib.py b/gvsbuild/projects/glib.py index eb3e684df..76929788b 100644 --- a/gvsbuild/projects/glib.py +++ b/gvsbuild/projects/glib.py @@ -40,6 +40,7 @@ def __init__(self): ], patches=[ "001-glib-package-installation-directory.patch", + "0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch", ], ) self.add_param("-Dman-pages=disabled") @@ -70,6 +71,7 @@ def __init__(self): dependencies=["glib-base"], patches=[ "001-glib-package-installation-directory.patch", + "0001-gsocket-windows-check-event-before-calling-WSAEnumNe.patch", ], ) self.add_param("-Dman-pages=disabled")