summaryrefslogtreecommitdiff
path: root/ovsdb
diff options
context:
space:
mode:
authorIlya Maximets <i.maximets@ovn.org>2021-09-23 01:47:24 +0200
committerIlya Maximets <i.maximets@ovn.org>2021-09-24 15:01:38 +0200
commit32b51326ef9c307b4acd0bacafb0218dd1372f3d (patch)
tree707ce89359c89bb398a9a054b2064518f1fbb3f5 /ovsdb
parentbb12b63176389e516ddfefce20dfa165f24430fb (diff)
downloadopenvswitch-32b51326ef9c307b4acd0bacafb0218dd1372f3d.tar.gz
ovsdb-data: Add function to apply diff in-place.
ovsdb_datum_apply_diff() is heavily used in ovsdb transactions, but it's linear in terms of number of comparisons. And it also clones all the atoms along the way. In most cases size of a diff is much smaller than the size of the original datum, this allows to perform the same operation in-place with only O(diff->n * log2(old->n)) comparisons and O(old->n + diff->n) memory copies with memcpy. Using this function while applying diffs read from the storage gives a significant performance boost and allows to execute much more transactions per second. Signed-off-by: Ilya Maximets <i.maximets@ovn.org> Acked-by: Mark D. Gray <mark.d.gray@redhat.com>
Diffstat (limited to 'ovsdb')
-rw-r--r--ovsdb/file.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/ovsdb/file.c b/ovsdb/file.c
index 59220824f..9f44007d9 100644
--- a/ovsdb/file.c
+++ b/ovsdb/file.c
@@ -113,19 +113,17 @@ ovsdb_file_update_row_from_json(struct ovsdb_row *row, bool converting,
if (row_contains_diff
&& !ovsdb_datum_is_default(&row->fields[column->index],
&column->type)) {
- struct ovsdb_datum new_datum;
-
- error = ovsdb_datum_apply_diff(&new_datum,
+ error = ovsdb_datum_apply_diff_in_place(
&row->fields[column->index],
&datum, &column->type);
ovsdb_datum_destroy(&datum, &column->type);
if (error) {
return error;
}
- ovsdb_datum_swap(&datum, &new_datum);
+ } else {
+ ovsdb_datum_swap(&row->fields[column->index], &datum);
+ ovsdb_datum_destroy(&datum, &column->type);
}
- ovsdb_datum_swap(&row->fields[column->index], &datum);
- ovsdb_datum_destroy(&datum, &column->type);
}
return NULL;