[PATCH] ui: Optimization dirty rect empty check logic

lijiejun posted 1 patch 1 year ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20231125075408.131075-1-a._5Flijiejun@163.com
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
ui/spice-display.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
[PATCH] ui: Optimization dirty rect empty check logic
Posted by lijiejun 1 year ago
Reduce unnecessary code execution in function qemu_spice_create_update,
such as "int blocks = DIV_ROUND_UP(surface_width(ssd->ds), blksize);"
and "int bpp = surface_bytes_per_pixel(ssd->ds);".

Signed-off-by: lijiejun <a_lijiejun@163.com>
---
 ui/spice-display.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/ui/spice-display.c b/ui/spice-display.c
index 6eb98a5a5c..508e35ed0f 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -194,10 +194,6 @@ static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
     int bpp = surface_bytes_per_pixel(ssd->ds);
     uint8_t *guest, *mirror;
 
-    if (qemu_spice_rect_is_empty(&ssd->dirty)) {
-        return;
-    };
-
     dirty_top = g_new(int, blocks);
     for (blk = 0; blk < blocks; blk++) {
         dirty_top[blk] = -1;
@@ -488,7 +484,9 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
 
     WITH_QEMU_LOCK_GUARD(&ssd->lock) {
         if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
-            qemu_spice_create_update(ssd);
+            if (!qemu_spice_rect_is_empty(&ssd->dirty)) {
+                qemu_spice_create_update(ssd);
+            }
             ssd->notify++;
         }
     }
-- 
2.25.1
Re: [PATCH] ui: Optimization dirty rect empty check logic
Posted by Marc-André Lureau 1 year ago
Hi

On Sat, Nov 25, 2023 at 11:55 AM lijiejun <a_lijiejun@163.com> wrote:
>
> Reduce unnecessary code execution in function qemu_spice_create_update,
> such as "int blocks = DIV_ROUND_UP(surface_width(ssd->ds), blksize);"
> and "int bpp = surface_bytes_per_pixel(ssd->ds);".
>
> Signed-off-by: lijiejun <a_lijiejun@163.com>

This is a micro-optimization which makes the
qemu_spice_create_update() less complete, mixing caller/callee
responsibilities.

> ---
>  ui/spice-display.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/ui/spice-display.c b/ui/spice-display.c
> index 6eb98a5a5c..508e35ed0f 100644
> --- a/ui/spice-display.c
> +++ b/ui/spice-display.c
> @@ -194,10 +194,6 @@ static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
>      int bpp = surface_bytes_per_pixel(ssd->ds);
>      uint8_t *guest, *mirror;
>
> -    if (qemu_spice_rect_is_empty(&ssd->dirty)) {
> -        return;
> -    };
> -
>      dirty_top = g_new(int, blocks);
>      for (blk = 0; blk < blocks; blk++) {
>          dirty_top[blk] = -1;
> @@ -488,7 +484,9 @@ void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd)
>
>      WITH_QEMU_LOCK_GUARD(&ssd->lock) {
>          if (QTAILQ_EMPTY(&ssd->updates) && ssd->ds) {
> -            qemu_spice_create_update(ssd);
> +            if (!qemu_spice_rect_is_empty(&ssd->dirty)) {
> +                qemu_spice_create_update(ssd);
> +            }
>              ssd->notify++;
>          }
>      }
> --
> 2.25.1
>
>


-- 
Marc-André Lureau