<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vaclav Loffelmann on Medium]]></title>
        <description><![CDATA[Stories by Vaclav Loffelmann on Medium]]></description>
        <link>https://medium.com/@vaclav.loffelmann?source=rss-1312c4678efd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z0fjMtjHa5E5n8c5u3OMXA.jpeg</url>
            <title>Stories by Vaclav Loffelmann on Medium</title>
            <link>https://medium.com/@vaclav.loffelmann?source=rss-1312c4678efd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 13:59:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vaclav.loffelmann/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vectorizing database operations with AVX-512]]></title>
            <link>https://medium.com/@vaclav.loffelmann/vectorizing-database-operations-with-avx-512-e759ce59abd3?source=rss-1312c4678efd------2</link>
            <guid isPermaLink="false">https://medium.com/p/e759ce59abd3</guid>
            <category><![CDATA[database-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hpc]]></category>
            <category><![CDATA[avx-512]]></category>
            <dc:creator><![CDATA[Vaclav Loffelmann]]></dc:creator>
            <pubDate>Mon, 05 Nov 2018 10:02:11 GMT</pubDate>
            <atom:updated>2018-11-05T10:29:27.340Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>TL;DR:</blockquote><blockquote>Given enough time it is possible to outperform compilers in vectorization and databases can be a lot faster if they would properly use AVX-512.</blockquote><p>It’s 2018 and C/C++ compilers are pretty good at generating well optimized code. It is hard to write more performant code than a compiler can generate except using some domain specific knowledge i.e. inlining some CMOV instructions or other low-level tricks. In these scenarios the focus is on just a subset of the code. But what if we look at the whole design from a different point of view? What if we take vector processing (SIMD) as if it was (almost) the only tool we have for the data processing? Then we would naturally end up with a vector-at-a-time processing where size of that vector is defined by the underlying hardware. Let’s call that <strong>vector-register-at-a-time</strong> processing (VRAAT). For instance, we consider latest vector instruction set on the Intel CPUs — <em>AVX-512</em>, which gives us 512 bit width vector registers. That means we can manipulate with up to 8 double precision numbers or 16 single precision numbers or 64 one byte elements.</p><h4>AVX-512 sidenote</h4><blockquote>The size of the registers is not the only benefit of this instruction set. Amount of addressable registers is also stunning, we can use up to 32 of these registers. Except that we have seven (plus one implicit) dedicated mask registers available as well. With the mask registers we control on which elements of the vector will computation be done. On top of that AVX-512 was extended by a numerous new instructions types like compress/expand, various types of shuffling, conflict detection, etc.</blockquote><h3>AVX-512 &amp; Compilers</h3><p>The question is, can compilers fully utilize the AVX-512 instruction set? Can compilers avoid (non-trivial) branching using masked instructions? Can they vectorize even slightly complex code? Can they correctly predict when vectorization will be beneficial at all?<br>As of now (GCC 8, Clang 7, ICC 18) the answer to all these questions is simple no.</p><p>There are multiple reasons why compilers cannot (would not) successfully vectorize your code right now. First of all, there is some overhead when switching between scalar and vector instructions. Execution units performing vector operations need to be <em>warmed-up, </em>so the amount of computation must be significant in order to get better performance. The next thing is that these execution units run at a lower frequency than a scalar counterparts, hence vector computation containing N elements would not be N times faster than scalar instructions. Not to mention that CPU can actually schedule multiple scalar instructions (of course, if there is no dependency) in one clock tick.</p><h3>Vectorizing database operations</h3><p>As an example of how system can be designed to use vector instructions from top to bottom we choose to implement compiler from SQL aggregate queries into the fully vectorized code. Why SQL queries? Because there actually <em>is </em>a lot of a headroom for speeding things up when aggregating data in the databases. One of the successful attempts for vector processing and hence step forward to the vector instructions was MonetDB/X100 [3], with their <strong>vector-at-a-time </strong>processing. Instead of processing row-at-a-time or column-at-a-time they choose to process columns divided into smaller pieces — vectors. These vectors can easily be fitted in the CPU cache, allowing passing the data between stages of processing in the CPU cache, avoid long stalls due to waits for the data from the main memory. The second benefit of this approach is, code can be vectorized, theoretically. Simply rely on the compiler to generate vectorized code is not enough, if we want to use the AVX-512 instruction set.</p><h3>Vector-register-at-a-time processing</h3><p>If we push vector-at-a-time processing a little further, we can keep the data between some operations even in the registers. We can look at this as a some kind of chain of inline functions. What’s preventing us to do so in current database design?</p><p>In the vector-at-a-time processing the data are passed through cache, thus forbid such optimization. In the row-at-a-time processing, this could be done only with scalar values if we actually <em>compile </em>the query (e.g. [2]).</p><p>But what if, the only way how to process data was to use the vector operations using vectors of size matching underlying hardware? Actually, there are only a few cases, where keeping data only in registers is possible. In fact, there are much more cases, when we have to work with memory, for instance sorting and group by aggregations.</p><p>Our proposal is to vectorize all possible operations and if possible pass data in the vector registers between these operations. For example AVX-512 sort already exists [1] and for group by aggregations/hash joins we need vectorized hash tables. Using B-tree indexes? Why not vectorize them either?</p><h3>Compile SQL aggregate queries into the AVX-512</h3><p>The ultimate goal was to maximize usage of SIMD instruction during the query execution. Prototype of such approach was developed. This program takes input query and runs it against abstraction of a table (table is basically map of arrays, where each array is single column).</p><p>In the first step of processing, the query is parsed and three parts of the query runtime are emitted. The first part is query initialization, there are some check for table/columns availability and initialization of accumulators for query results. Second part is content of a loop iterating over the data. In this loop the data are loaded into the vector registers, then filtered and aggregated. The last section of emitted code just finalizes aggregations and returns data.</p><p>The most interesting is the second part, so let us present the example of generated middle part (body of the loop) of the following query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24bc6cc6cfad4e836b04d6361bf349e1/href">https://medium.com/media/24bc6cc6cfad4e836b04d6361bf349e1/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3de5ec480a4a707555074170bb8b6f5d/href">https://medium.com/media/3de5ec480a4a707555074170bb8b6f5d/href</a></iframe><p>As You can see, this code contains C/C++ intrinsics and some wrappers around them (load function, aggregators, mask operations). When compiled, this produces very few instructions and is blazingly fast. How fast is that? Let’s compare that to hand-written straightforward C++ code doing the same thing using the standard library.</p><p>Consider following 12 queries. First 6 queries using simple aggregate and rest of queries using aggregation with GROUP BY clause.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/963496ca099cdfc1e415b77332a78555/href">https://medium.com/media/963496ca099cdfc1e415b77332a78555/href</a></iframe><p>“Table” <strong>t1</strong> have 20M rows and columns<strong> a-f</strong> contains following integer data:</p><ul><li><strong>a, </strong>Row id, 0–20M</li><li><strong>b, </strong>Row id * 2, 0–40M</li><li><strong>c, </strong>Pseudo random 0 or 1</li><li><strong>d, </strong>Pseudo random from 0 to 99</li><li><strong>e, </strong>Altering 0/1</li><li><strong>f, </strong>Repeating sequence 0–9</li></ul><p>Scalar code was compiled by the GCC 8 and Clang 6 and execution times compared to the generated SIMD code (VRAAT).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3P2LG2urL2Z7rhUt" /></figure><p>As we can see compilers was able to generate vectorized (and same performant) code only for the first (easiest) query. The rest of the simple aggregate queries 2–5, was speeded more than 5 times with vectorized execution. None of available compilers (GCC, Clang, ICC) were able to vectorize those codes. Queries 7–10 (containing GROUP BY statement) was slightly faster implemented with SIMD. On average, by 24% on queries 7–12. Query 11 and 12 hit the performance limitation with concurrent memory access (discussed later).</p><h3>Prototype limitations</h3><p>This program was created to handle only 64 bit integer values. Queries 1–6 would be even faster using 32 bit numbers, because there would be two times more items in the vector registers and most of the vector instructions would take the same amount of time. One great drawback would be that concurrent L1 cache misses would be drained even sooner, making group by aggregations probably somewhat slower.</p><p>If we would allow mixing multiple data types in one query, we would run into other problems as well. Logic for generating vector code would be much more complex because vector register width would stay the same for every data type, but number of containing elements would differ. For instance, combining ints and longs would require twice as much instructions for long values. Such design would require some abstraction over the native registers and operations.</p><p>Filtering by setting bits in the mask is not the only way how to effectively control the flow. Depending on the condition selectivity other strategies can be used. With low selectivity, one can utilize the <em>compress </em>instruction which shrinks the data inside the vector and then bypass next stages of the process. Within next pass data from previous iteration can be merged and process next stages of computing only once. With really small selectivity a whole mask of the vector can be checked for validity and if none of the elements would be valid all further computation can be skipped. Of course different strategies can be selected at runtime if related statistics are collected.</p><h3>Vectorized Hash Table</h3><p>There are three common operations related to the hash tables: hash computation and read or write values into the table. All of these operations can be vectorized, but the only question is if it comes with a performance benefit. Hashing can be easily vectorized and there is no doubt using SIMD instructions will result in greater throughput. Vector read/write operations can be done with gathers/scatters instructions. But there is one big limitation in the current x86 chips when it comes to a parallel access to the memory. That limitation is <em>Line Fill Buffer </em>(LFB), which can handle only 10 concurrent L1D cache misses per core. Considering that one gather instruction can emit up to 16 memory accesses this is a serious restriction. With instruction reordering even the scalar code can hit this limit, not even talking about hyperthreading, where LFB is a shared resource. But the scalar code does not suffer so much because unfinished reads does not (always) block further execution, whereas gather instruction must wait till all vector elements are loaded.</p><p>Second issue with vectorized hash tables is collisions of input elements. Depending on use-case this may or may not happen. There are multiple approaches how to deal with these collisions: 1) scalar conflict detection 2) vector conflict detection 3) partitioning the backing table.</p><p>Scalar solution can often be faster than a vector <em>VPCONFLICTD/Q </em>instruction, which for 512 bit vector takes around 26 clocks for 32 bit elements and 17 clocks for 64 bit elements respectively.</p><p>The third solution — backing table partitioning, was experimentally implemented within this project and it was able to outperform default <em>std::unrodered_map</em> only for a few elements and soon start hitting the limitation of LFB.</p><blockquote><strong>Conclusion: </strong>vectorized hash table implementation is worth further research after CPU vendors allow handling more concurrent L1D misses.</blockquote><h3>Vectorized B+tree search</h3><p>Let’s look how B+tree search can be vectorized. It is known that in modern CPUs asymptotic complexity does not always reflect the actual algorithm performance, thanks to various optimizations, e.g. speculative execution, instruction level parallelism, SIMD, multiple levels of cache, etc. Hence linear search with worse complexity can outperform binary search on small datasets. This fact is utilized in hybrid search approach. Testing program form [4] was extended by vectorized AVX-512 linear search. See results in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/0*arGmlSwCQoOSaCRX" /></figure><p>We can see, that AVX-512 linear search is faster than binary for up to 128 elements. Just only as a proof of concept it was implemented AVX-512 search over B+tree elements where branching factor was set to 16 and compared with two implementations <em>stx::btree</em> and <em>std::map</em>.</p><p>The implementation is pretty straightforward. Search is implemented by loading keys into the vector registers, then compared to requested key which produces a bit mask. After that number of smaller elements are counted (<em>POPCNT</em> over the bit mask) and following node address is determined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_MVDDTpHzRAxSgsl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*anJglNlUR__2G5d4" /></figure><h3>MVCC &amp; Masked instructions</h3><p>One major functionality of databases is multiversioning. Simply speaking, we can look on the multiversioning as a tuples of value:timestamp. And depending on deletion/update strategy data deletion/invalidation is just set proper bit. With proper DB design, we can fully utilize masked instructions for making computation only on valid data and despite the fact that masked instructions are first-class citizen in the AVX-512, DB engine of this design would perform really well.</p><h3>Conclusion</h3><p>When it comes to compute intensive tasks AVX-512 is really performant and unfortunately current compilers cannot fully utilize it. With a great deal of low-level work it is (again) possible to beat the compiler by multiple times on some workloads. Memory intensive tasks often suffer from LFB limitations, but there is a great probability that the next CPU generations this obstacle will be eliminated and success of AVX-512 can be expanded even over more algorithmic domains.</p><p>One drawback is that AVX-512 is exclusively provided only by one CPU vendor and its electric circuits occupy a considerable amount of chip die and no one can really be sure that AVX-512 will not be omitted in favour of more CPU cores.</p><h3>References</h3><p>[1] BRAMAS, B. A Novel Hybrid Quicksort Algorithm Vectorized using AVX-512 on Intel Skylake. International Journal of Advanced Computer Science and Applications (IJACSA) . 2017.</p><p>[2] BUTTERSTEIN, D. GRUST, T. Precision performance surgery for CostgreSQL: LLVMbased Expression Compilation, Just in Time. Proceedings of the VLDB Endowment . 2016, 9, 13, s. 15171520.</p><p>[3] ZUKOWSKI, M. et al. MonetDB/X100 — A DBMS In The CPU Cache.IEEE Data Eng. Bull. 2005, 28, 2, s. 1722.</p><p>[4] <a href="https://dirtyhandscoding.wordpress.com/2017/08/25/performance-comparison-linear-search-vs-binary-search/">https://dirtyhandscoding.wordpress.com/2017/08/25/performance-comparison-linear-search-vs-binary-search/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e759ce59abd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The World’s First Middle-Out Compression for Time-series Data — Part 2]]></title>
            <link>https://medium.com/@vaclav.loffelmann/the-worlds-first-middle-out-compression-for-time-series-data-part-2-40c048632911?source=rss-1312c4678efd------2</link>
            <guid isPermaLink="false">https://medium.com/p/40c048632911</guid>
            <category><![CDATA[compression]]></category>
            <category><![CDATA[avx-512]]></category>
            <category><![CDATA[silicon-valley]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[middle-out]]></category>
            <dc:creator><![CDATA[Vaclav Loffelmann]]></dc:creator>
            <pubDate>Mon, 20 Nov 2017 17:45:42 GMT</pubDate>
            <atom:updated>2017-11-20T17:45:42.327Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Since the dawn of time mankind hath sought to make things smaller…</blockquote><blockquote>Erlich Blachman</blockquote><p>In the <a href="https://medium.com/@vaclav.loffelmann/the-worlds-first-middle-out-compression-for-time-series-data-part-1-1e5ad5312757">previous part</a> we presented the results of our new Middle-out compression algorithm for time-series data. Today we are going to dive deep into the technical details.</p><h3>The Middle-out Part</h3><p>We all know, how the Middle-out compression works at the HBO show [2], but how do we actually apply this to the time-series data?</p><p>Take a look at the following schema. There is an input vector of a data. This vector is divided to Middle-out segments. For simplicity, in the image there are only four of a segments, but compression actually uses eight. This is because the AVX-512 vector instructions can process up to 8 doubles at once. If we used a single precision numbers, then we’d have 16 Middle-out segments and proceed 16 elements at a time.</p><p>The first elements of each segment (denoted by blue) are referencing values. These values are stored as-is in the front of a compressed data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*f6SE7i-ms2R_uxLZ." /></figure><p>As long as we have multiple referencing points, we can compute diffs between the following values <em>in parallel</em>. That allows us to iterate through all Middle-out segments simultaneously, in the same block of the SIMD instructions. Within each iteration, the current values are XORed with the previous ones and the results of this operation are stored in one data block.</p><p>If there is a reminder of the division of the length of the input vector by the count of Middle-out blocks, values from that reminder are stored uncompressed at the end of compressed data.</p><p>Of course the uncompressed header and footer add some space overhead, but we assume that the overhead would be amortized among at least a few thousands values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*x2yLzLVnu8ez1gKS." /></figure><p>Each data block starts with a bit mask determining what values are the same as the previous ones. If the corresponding bit is set, then we know that the value didn’t change. If all of the bits are set, no further information is stored — all values are the same as the previous ones. In that case, we are able to store an unchanged value in just single bit.</p><p>Next, we store the right offsets (trailing zeros) rounded down to bytes. As long as we are addressing whole bytes, we need only 3 bits to store that offset. Only the offsets respective to the changed values are stored. Then the max length (within this block) of the non-zero XORed value is stored. This length holds bytes as well, and we know the max length could not be 0; that would mean all the values are the same as the previous ones and we wouldn’t store this information at all. Hence we need to store only lengths from 1 to 8 that can be stored in 3 bits. We store length only once per block, because we assume that all compressed data would have, in general, the same characteristics, i.e. changing by approximately the same value. All these values encoded in 3 bits (offsets and length) are conjoined and an optional padding is inserted if needed to reach the byte boundary.</p><p>Lastly, the XORs parts are stored at the end of the the data block.</p><h3>How This Compression Benefits from the AVX-512</h3><p>We have two implementations, one using vector instructions and the other don’t. And we see AVX-512 offers great speedup, in fact, it is the first instruction set which offers all vector instructions essential for this algorithm.</p><p>First of all, it is a vector <em>leading zeros count</em> instruction. AVX2 does not offer such instruction, so the data would have to be moved back and forth between scalar and vector registers.</p><p>Gather instructions (loading data to a vector from a different locations of a memory) was already introduced in the AVX2, but its counterpart — <em>Scatter </em>(storing data) has finally arrived and been incorporated in the AVX-512. Did you know that the scatters can actually be used as compression instructions? One simple trick is to write to overlapping addresses. It is guaranteed that these stores will be executed in one particular order. Not using this optimization, compression crossing vector elements boundaries would be far more expensive.</p><p>The next step forward in the AVX-512 is a support for <em>masked instructions</em> with a dedicated mask registers. Bit mask allows to specify elements on which computation should be performed. This allows us to ged rid of a unpredictable branching in performance critical loops.</p><p>There is even an instruction actually called <em>compress</em>. This instruction contiguously store only selected elements from a source vector to another vector, or to a memory location.</p><h3>Conclusion</h3><p>We tuned our implementations to squeeze out every bit of performance. We made sure not even a single instruction is wasted. For instance, vector implementation of the inner loop for decompression has only about 80 instructions total. That is about 10 CPU instructions per a decompressed value.</p><p>As it turns out, the middle-out approach can have a significant benefits in data processing and we are going to investigate other areas where it could be applied. If You have any challenging task that could benefit from the vector instructions, feel free to contact us.</p><p>Source codes of the vectorized and the scalar implementation can be found on the Github [1].</p><p>[1] <a href="https://github.com/schizofreny/middle-out">https://github.com/schizofreny/middle-out</a></p><p>[2] <a href="https://vimeo.com/97107551">https://vimeo.com/97107551</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=40c048632911" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The World’s First Middle-Out Compression for Time-series Data — Part 1]]></title>
            <link>https://medium.com/@vaclav.loffelmann/the-worlds-first-middle-out-compression-for-time-series-data-part-1-1e5ad5312757?source=rss-1312c4678efd------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e5ad5312757</guid>
            <category><![CDATA[middle-out]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[silicon-valley]]></category>
            <category><![CDATA[avx-512]]></category>
            <category><![CDATA[compression]]></category>
            <dc:creator><![CDATA[Vaclav Loffelmann]]></dc:creator>
            <pubDate>Mon, 02 Oct 2017 21:03:35 GMT</pubDate>
            <atom:updated>2021-10-31T21:20:25.317Z</atom:updated>
            <content:encoded><![CDATA[<p>UPDATE: Algorithm is now licensed under WTFPLv2. Source codes available at <a href="https://github.com/schizofreny/middle-out">https://github.com/schizofreny/middle-out</a>.</p><p>Middle-out compression is no longer a fictional invention from<a href="http://www.imdb.com/title/tt2575988/"> HBO’s show <em>Silicon Valley</em></a>. Inspired by both the TV show and new vector instruction sets, we came up with a new lossless compression algorithm for time-series data. Compression is <em>always</em> about a compromise between speed and ratio and It is never easy to balance these trade-offs, but the whole middle-out concept allows us to push <a href="https://en.wikipedia.org/wiki/Weissman_score">Weissman score</a> even further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Miw8k0lvZNL4KxTpRlf9jw.png" /><figcaption><a href="https://moviecode.tumblr.com/post/143666368582/silicon-valley-s03e01-its-not-obvious-what-the">Source code of Pied Paper’s compression algorithm</a></figcaption></figure><h3>What Is So Special about Middle-Out Compression?</h3><p>It simply breaks data dependency. If we need a previous value to compute a current one, we need <em>all</em> antecedent values. But if we start processing from multiple positions of the chunk we depend only on antecedent values within this fragment. This allows us, for instance, to effectively use SIMD instructions.</p><h3>How Does it Work?</h3><p>In principle, the algorithm computes the XOR of a new value and the previous one. This way we get a sort of diff between values and we can store this diff alone. In time-series datasets this diff typically has a number of either leading and/or trailing zeroes. Hence the information we need to store is usually significantly smaller, but we also need to store leading zeros count and length of non-zero XOR fragment.</p><p>These concepts are generally used in current compressions algorithms, e.g. Facebook’s Gorilla [1]. For the sake of compression efficiency, Gorilla operates on bits level, but these operations are quite expansive. We have designed our compression to be as <em>fast</em> as possible so we moved from bit to byte granularity. As a consequence, one would expect worse compression ratio, but that is not always the case.</p><p>With regard to middle-out, compression operates on blocks of data, but this is not a problem as time-series databases uses blocks anyway.</p><h3>What About Compression Ratio?</h3><p>Let’s examine compression ratio in two different scenarios. The first scenario — we take a series of doubles (i.e. 0.1, 0.2, 0.3, …) and measure compression ratio depending on the portion of repeating points. For comparison we use Facebook’s Gorilla compression. By default Gorilla compresses both the values and timestamps of time-series data. For our test purposes, compression of timestamps is disabled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SXHclRv8FCWNSw25." /></figure><p>It isn’t surprising to find that Gorilla has slightly better compression ratio for these types of data. We can see the same trend with long-integer sequences.</p><p>Second scenario — datasets. Datasets A and B share the same minute stock data. In the case of dataset A, price points are compressed as floating point numbers. In dataset B these numbers are first multiplied to shift the decimal point and hence we can represent these numbers as long without losing precision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2TjiwF9e0iET4-Oa." /></figure><p>Datasets C and D are generated using a benchmarking tool from InfluxData [2]: representing disk writes and redis memory usage. In the case of dataset A, Gorilla compresses data slightly better than our algorithm — with a ratio of 1.45 vs 1.3. Other datasets using integers are better compressed with our new algorithm. The biggest difference can be seen in dataset D where the Middle-out compression ratio is 3.3, whereas Gorilla can compress these data only with a ratio of 1.84. Compression ratio substantially depends on the input of data and there are obviously datasets where one algorithm compresses better than another. But if performance is your concern — keep reading.</p><h3>Compression Performance</h3><p>Currently we have two compatible implementations of the algorithm. One utilizes a new AVX-512 instruction set available on Skylake-X CPUs. The second implementation targets computers without the support of this instruction set.</p><p>Throughput is measured on a single core of Skylake-X running at 2.0 GHz.</p><p>The following charts show the compression and decompression speed of both implementations compared to Facebook’s Gorilla.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*krWx_PaWm4R25gNE." /></figure><p>This graph shows compression throughput as measured on the four datasets discussed above, plus the throughput of a series with the respective percentage of repeating values.</p><p>The throughput of Gorilla compression varies from 120–440 MB/s with an average speed of 185 MB/s. The lowest throughput of our scalar implementation compresses around 670 MB/s for 50% of repeating values. This is due to a high branch misprediction ratio. The average compression speed is 1.27 GB/s. An algorithm using vector instructions does not suffer from branch misprediction and compresses data from 2.33 GB/s to 2.59 GB/s, with an average speed of 2.48 GB/s. Not bad for a single core of 2 GHz chip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jODK2EsXwazbCq5i." /></figure><p>Gorilla can decompress these data at speeds ranging from 100 MB/s to 430 MB/s . But as you can see, our decompression of the same data is even faster than a compression. Non-vectorized decompression operates at a minimal speed of 2.36 GB/s and 2.7 GB/s on average. Vectorized codes decompress data from 3.4 GB/s, hitting 4.86 GB/s for dataset D. On average it is able to decompress the data at 4.0 GB/s.</p><p>The average <strong>overall speedup</strong> for compression is 6.8x (scalar implementation) and <strong>13.4x</strong> (vectorized implementation). The average speedup for decompression is 16.1x and <strong>22.5x</strong> respectively.</p><blockquote><a href="https://medium.com/@vaclav.loffelmann/the-worlds-first-middle-out-compression-for-time-series-data-part-2-40c048632911">Part II</a></blockquote><p>[1] <a href="http://www.vldb.org/pvldb/vol8/p1816-teller.pdf">www.vldb.org/pvldb/vol8/p1816-teller.pdf</a></p><p>[2] <a href="https://github.com/influxdata/influxdb-comparisons/">https://github.com/influxdata/influxdb-comparisons/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e5ad5312757" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>