diff mbox series

[ovs-dev,4/4] ovsdb: row: Optimize row updates by applying diffs in-place.

Message ID 20211219140941.2279071-5-i.maximets@ovn.org
State Accepted
Commit 015994d37fa441844f9c0890109074b06e64e7d0
Headers show
Series ovsdb: Bug fixes + Relay txn history and performance. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Ilya Maximets Dec. 19, 2021, 2:09 p.m. UTC
ovsdb_datum_apply_diff_in_place() is much faster than the usual
ovsdb_datum_apply_diff() in most cases, because it doesn't clone or
compare unnecessary data.  Since the original destination datum is
destroyed anyway, we might use the faster function here to speed up
transaction processing.

ovsdb_row_update_columns() with xor is mainly used by relay databases.
So, this change should improve their performance.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 ovsdb/row.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

Comments

Mike Pattrick Jan. 7, 2022, 8:46 p.m. UTC | #1
On Sun, 2021-12-19 at 15:09 +0100, Ilya Maximets wrote:
> ovsdb_datum_apply_diff_in_place() is much faster than the usual
> ovsdb_datum_apply_diff() in most cases, because it doesn't clone or
> compare unnecessary data.  Since the original destination datum is
> destroyed anyway, we might use the faster function here to speed up
> transaction processing.
> 
> ovsdb_row_update_columns() with xor is mainly used by relay databases.
> So, this change should improve their performance.
> 
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
>  ovsdb/row.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 

Looks good to me!

Acked-by: Mike Pattrick <mkp@redhat.com>



> diff --git a/ovsdb/row.c b/ovsdb/row.c
> index e83c60a21..40f53b0a5 100644
> --- a/ovsdb/row.c
> +++ b/ovsdb/row.c
> @@ -244,24 +244,18 @@ ovsdb_row_update_columns(struct ovsdb_row *dst,
>  
>      for (i = 0; i < columns->n_columns; i++) {
>          const struct ovsdb_column *column = columns->columns[i];
> -        struct ovsdb_datum xor_datum;
>          struct ovsdb_error *error;
>  
>          if (xor) {
> -            error = ovsdb_datum_apply_diff(&xor_datum,
> -                                           &dst->fields[column->index],
> -                                           &src->fields[column->index],
> -                                           &column->type);
> +            error = ovsdb_datum_apply_diff_in_place(
> +                            &dst->fields[column->index],
> +                            &src->fields[column->index],
> +                            &column->type);
>              if (error) {
>                  return error;
>              }
> -        }
> -
> -        ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
> -
> -        if (xor) {
> -            ovsdb_datum_swap(&dst->fields[column->index], &xor_datum);
>          } else {
> +            ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
>              ovsdb_datum_clone(&dst->fields[column->index],
>                                &src->fields[column->index],
>                                &column->type);
Han Zhou Jan. 25, 2022, 5:58 p.m. UTC | #2
On Sun, Dec 19, 2021 at 6:09 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> ovsdb_datum_apply_diff_in_place() is much faster than the usual
> ovsdb_datum_apply_diff() in most cases, because it doesn't clone or
> compare unnecessary data.  Since the original destination datum is
> destroyed anyway, we might use the faster function here to speed up
> transaction processing.
>
> ovsdb_row_update_columns() with xor is mainly used by relay databases.
> So, this change should improve their performance.
>
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
>  ovsdb/row.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/ovsdb/row.c b/ovsdb/row.c
> index e83c60a21..40f53b0a5 100644
> --- a/ovsdb/row.c
> +++ b/ovsdb/row.c
> @@ -244,24 +244,18 @@ ovsdb_row_update_columns(struct ovsdb_row *dst,
>
>      for (i = 0; i < columns->n_columns; i++) {
>          const struct ovsdb_column *column = columns->columns[i];
> -        struct ovsdb_datum xor_datum;
>          struct ovsdb_error *error;
>
>          if (xor) {
> -            error = ovsdb_datum_apply_diff(&xor_datum,
> -                                           &dst->fields[column->index],
> -                                           &src->fields[column->index],
> -                                           &column->type);
> +            error = ovsdb_datum_apply_diff_in_place(
> +                            &dst->fields[column->index],
> +                            &src->fields[column->index],
> +                            &column->type);
>              if (error) {
>                  return error;
>              }
> -        }
> -
> -        ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
> -
> -        if (xor) {
> -            ovsdb_datum_swap(&dst->fields[column->index], &xor_datum);
>          } else {
> +            ovsdb_datum_destroy(&dst->fields[column->index],
&column->type);
>              ovsdb_datum_clone(&dst->fields[column->index],
>                                &src->fields[column->index],
>                                &column->type);
> --
> 2.31.1
>

Acked-by: Han Zhou <hzhou@ovn.org>
Ilya Maximets March 3, 2022, 6:11 p.m. UTC | #3
On 1/7/22 21:46, Mike Pattrick wrote:
> On Sun, 2021-12-19 at 15:09 +0100, Ilya Maximets wrote:
>> ovsdb_datum_apply_diff_in_place() is much faster than the usual
>> ovsdb_datum_apply_diff() in most cases, because it doesn't clone or
>> compare unnecessary data.  Since the original destination datum is
>> destroyed anyway, we might use the faster function here to speed up
>> transaction processing.
>>
>> ovsdb_row_update_columns() with xor is mainly used by relay databases.
>> So, this change should improve their performance.
>>
>> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
>> ---
>>  ovsdb/row.c | 16 +++++-----------
>>  1 file changed, 5 insertions(+), 11 deletions(-)
>>
> 
> Looks good to me!
> 
> Acked-by: Mike Pattrick <mkp@redhat.com>

Thanks, Mike an Han!
Applied.

Best regards, Ilya Maximets.
diff mbox series

Patch

diff --git a/ovsdb/row.c b/ovsdb/row.c
index e83c60a21..40f53b0a5 100644
--- a/ovsdb/row.c
+++ b/ovsdb/row.c
@@ -244,24 +244,18 @@  ovsdb_row_update_columns(struct ovsdb_row *dst,
 
     for (i = 0; i < columns->n_columns; i++) {
         const struct ovsdb_column *column = columns->columns[i];
-        struct ovsdb_datum xor_datum;
         struct ovsdb_error *error;
 
         if (xor) {
-            error = ovsdb_datum_apply_diff(&xor_datum,
-                                           &dst->fields[column->index],
-                                           &src->fields[column->index],
-                                           &column->type);
+            error = ovsdb_datum_apply_diff_in_place(
+                            &dst->fields[column->index],
+                            &src->fields[column->index],
+                            &column->type);
             if (error) {
                 return error;
             }
-        }
-
-        ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
-
-        if (xor) {
-            ovsdb_datum_swap(&dst->fields[column->index], &xor_datum);
         } else {
+            ovsdb_datum_destroy(&dst->fields[column->index], &column->type);
             ovsdb_datum_clone(&dst->fields[column->index],
                               &src->fields[column->index],
                               &column->type);