From 70c80e19e6c167a0d7eb30a8604fe70a8f81fb8d Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Tue, 12 May 2020 17:51:16 -0700 Subject: [PATCH] [greedy] Fix performance instability --- lib/compress/zstd_lazy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/compress/zstd_lazy.c b/lib/compress/zstd_lazy.c index 67ed07cba..4cf5c88b5 100644 --- a/lib/compress/zstd_lazy.c +++ b/lib/compress/zstd_lazy.c @@ -681,6 +681,12 @@ ZSTD_compressBlock_lazy_generic( } /* Match Loop */ +#if defined(__GNUC__) && defined(__x86_64__) + /* I've measured random a 5% speed loss on levels 5 & 6 (greedy) when the + * code alignment is perturbed. To fix the instability align the loop on 32-bytes. + */ + __asm__(".p2align 5"); +#endif while (ip < ilimit) { size_t matchLength=0; size_t offset=0; @@ -952,6 +958,12 @@ size_t ZSTD_compressBlock_lazy_extDict_generic( ip += (ip == prefixStart); /* Match Loop */ +#if defined(__GNUC__) && defined(__x86_64__) + /* I've measured random a 5% speed loss on levels 5 & 6 (greedy) when the + * code alignment is perturbed. To fix the instability align the loop on 32-bytes. + */ + __asm__(".p2align 5"); +#endif while (ip < ilimit) { size_t matchLength=0; size_t offset=0; -- 2.47.2