ss_bsdiff: Fix to speed up patch generation 93/280093/3
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 23 Aug 2022 14:18:57 +0000 (16:18 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 23 Aug 2022 14:48:43 +0000 (14:48 +0000)
Modification created by Thieu Le <thieule@chromium.org> which speeds up
patch generation time in situations where large blocks of data differ by
less than 8 bytes.

This change originates from:

   https://android.googlesource.com/platform/external/bsdiff/+/d172820cb8b4513478f0db5546d6e4d388adc1a7

Change-Id: Iee52b3d3e469ab0850c22bb6858beb7654c229d8

bsdiff/ss_bsdiff.c

index b153a73dd4e0bf7674348f9d77f91e3e629eea45..76fbe41d8e22e3be6d92b8607d024c316f46f719 100755 (executable)
@@ -362,7 +362,13 @@ int Function(int offset_oldscore)
        lastoffset = 0;
        while (scan < end) {
                oldscore = 0;
+               size_t prev_len;
+               uint64_t prev_pos, prev_oldscore;
+               int num_less_than_eight = 0;
                for (scsc = scan += len; scan < end; scan++) {
+                       prev_len = len;
+                       prev_oldscore = oldscore;
+                       prev_pos = pos;
                        len = search(data.I, data.old, data.oldsize, data.new[thread_num] + scan, end - scan,
                                        len, data.oldsize, &pos); // Passing parameter as len instead of 0 for ramdisk.img etc taking long time
 
@@ -389,6 +395,24 @@ int Function(int offset_oldscore)
                        if ((scan + lastoffset < data.oldsize) &&
                                        (data.old[scan + lastoffset] == data.new[thread_num][scan]))
                                oldscore--;
+
+                       /*
+                        * Modification created by Thieu Le <thieule@chromium.org>
+                        * which speeds up patch generation time in situations
+                        * where large blocks of data differ by less than 8 bytes.
+                        * https://android.googlesource.com/platform/external/bsdiff/+/d172820cb8b4513478f0db5546d6e4d388adc1a7
+                        */
+                       const size_t fuzz = 8;
+                       if (prev_len - fuzz <= len && len <= prev_len &&
+                           prev_oldscore - fuzz <= oldscore &&
+                           prev_pos <= pos && pos <= prev_pos + fuzz &&
+                           oldscore <= len && len <= oldscore + fuzz) {
+                           num_less_than_eight++;
+                       } else {
+                               num_less_than_eight = 0;
+                       }
+                       if (num_less_than_eight > 100) break;
+
                };
                if ((len != oldscore) || (scan == end)) {
                        s = 0;