/// Lizard (LZ5) compression routines (statically linked for FPC) // - licensed under a MPL/GPL/LGPL tri-license; original Lizard is BSD 2-Clause unit SynLizard; { This file is part of Synopse Lizard Compression. Synopse Lizard Compression. Copyright (C) 2022 Arnaud Bouchez Synopse Informatique - https://synopse.info *** BEGIN LICENSE BLOCK ***** Version: MPL 1.1/GPL 2.0/LGPL 2.1 The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is Synopse Lizard Compression. The Initial Developer of the Original Code is Arnaud Bouchez. Portions created by the Initial Developer are Copyright (C) 2022 the Initial Developer. All Rights Reserved. Contributor(s): Alternatively, the contents of this file may be used under the terms of either the GNU General Public License Version 2 or later (the "GPL"), or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which case the provisions of the GPL or the LGPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of either the GPL or the LGPL, and not to allow others to use your version of this file under the terms of the MPL, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL or the LGPL. If you do not delete the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. ***** END LICENSE BLOCK ***** *** BEGIN ORIGINAL LICENSE BLOCK ***** Version: BSD 2-Clause License Lizard Library Copyright (C) 2011-2016, Yann Collet. Copyright (C) 2016-2017, Przemyslaw Skibinski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. You can contact the author at : - Lizard source repository : https://github.com/inikep/lizard ***** END ORIGINAL LICENSE BLOCK ***** Some numbers, for a 53MB log file (taken from a production server): FPC Win32 TAlgoSynLz 53 MB->5 MB: comp 563.7 MB/s decomp 815.3 MB/s TAlgoLizard 53 MB->3.9 MB: comp 54.6 MB/s decomp 1.1 GB/s TAlgoLizardFast 53 MB->6.9 MB: comp 493.8 MB/s decomp 1 GB/s TAlgoDeflate 53 MB->4.8 MB: comp 28.2 MB/s decomp 212 MB/s TAlgoDeflateFast 53 MB->7 MB: comp 58.6 MB/s decomp 182.5 MB/s FPC Win64 TAlgoSynLz 53 MB->5 MB: comp 635.4 MB/s decomp 923.5 MB/s TAlgoLizard 53 MB->3.9 MB: comp 61 MB/s decomp 1.8 GB/s TAlgoLizardFast 53 MB->6.8 MB: comp 674.2 MB/s decomp 1.6 GB/s TAlgoDeflate 53 MB->4.8 MB: comp 40.2 MB/s decomp 255.1 MB/s TAlgoDeflateFast 53 MB->7 MB: comp 81.2 MB/s decomp 219.9 MB/s FPC Linux32 TAlgoSynLz 53 MB->5 MB: comp 533.4 MB/s decomp 472.5 MB/s TAlgoLizard 53 MB->3.9 MB: comp 44.8 MB/s decomp 1.2 GB/s TAlgoLizardFast 53 MB->6.9 MB: comp 515.5 MB/s decomp 1 GB/s TAlgoDeflate 53 MB->4.8 MB: comp 60.2 MB/s decomp 413.3 MB/s TAlgoDeflateFast 53 MB->7 MB: comp 121.8 MB/s decomp 336.7 MB/s FPC Linux64 TAlgoSynLz 53 MB->5 MB: comp 626.4 MB/s decomp 906.8 MB/s TAlgoLizard 53 MB->3.9 MB: comp 53.6 MB/s decomp 1.8 GB/s TAlgoLizardFast 53 MB->6.8 MB: comp 700.3 MB/s decomp 1.6 GB/s TAlgoDeflate 53 MB->4.8 MB: comp 70.5 MB/s decomp 544.5 MB/s TAlgoDeflateFast 53 MB->7 MB: comp 141.4 MB/s decomp 420.2 MB/s Conclusion: SynLZ has the best compression ratio for its compression speed, but Lizard is much faster at decompression, when working with big log filesiles. For small files (= Lizard_compressBound(srcSize) // - returns number of bytes written into dst (necessarily <= maxDstSize), // or 0 if compression fails due to too small maxDstSize, <0 on other failure // - compressionLevel is from LIZARD_MIN_CLEVEL (10) to LIZARD_MAX_CLEVEL(49), // any value <10 (e.g. 0) will use 17, and value >49 will use 49 // $ Lev Comp Decomp CompSize Ratio // $ 7332 MB/s 8719 MB/s 211947520 100.00 (move) // $ 10 346 MB/s 2610 MB/s 103402971 48.79 // $ 12 103 MB/s 2458 MB/s 86232422 40.69 // $ 15 50 MB/s 2552 MB/s 81187330 38.31 // $ 19 3.04 MB/s 2497 MB/s 77416400 36.53 // $ 21 157 MB/s 1795 MB/s 89239174 42.10 // $ 23 30 MB/s 1778 MB/s 81097176 38.26 // $ 26 6.63 MB/s 1734 MB/s 74503695 35.15 // $ 29 1.37 MB/s 1634 MB/s 68694227 32.41 // $ 30 246 MB/s 909 MB/s 85727429 40.45 // $ 32 94 MB/s 1244 MB/s 76929454 36.30 // $ 35 47 MB/s 1435 MB/s 73850400 34.84 // $ 39 2.94 MB/s 1502 MB/s 69807522 32.94 // $ 41 126 MB/s 961 MB/s 76100661 35.91 // $ 43 28 MB/s 1101 MB/s 70955653 33.48 // $ 46 6.25 MB/s 1073 MB/s 65413061 30.86 // $ 49 1.27 MB/s 1064 MB/s 60679215 28.63 compress: function(src, dst: pointer; srcSize, maxDstSize, compressionLevel: integer): integer; cdecl; /// how much memory must be allocated for compress_extState() sizeofState: function(compressionLevel: integer): integer; cdecl; /// compresses using an external pre-allocated state buffer compress_extState: function(state: pointer; src, dst: pointer; srcSize, maxDstSize, compressionLevel: integer): integer; cdecl; /// decompresses srcSize bytes from src into already allocated dst buffer // - returns number of bytes written to dst (<= maxDstSize), or <=0 on failure // - this function is protected against buffer overflow exploits decompress_safe: function(src, dst: pointer; srcSize, maxDstSize: integer): integer; cdecl; /// partial decompression srcSize bytes from src into already allocated dst buffer // - returns number of bytes written to dst (<= maxDstSize), or <=0 on failure // - number can be 1 then if aRaiseNoException then exit else raise Exception.CreateFmt('%s has unexpected versionNumber=%d', [fLibraryName, versionNumber]); inherited Create; // register AlgoLizard/AlgoLizardFast/AlgoLizardHuffman fLoaded := true; end; destructor TSynLizardDynamic.Destroy; begin {$ifdef BSDNOTDARWIN} if fHandle<>TLibHandle(nil) then dlclose(fHandle); {$else} if fHandle<>0 then FreeLibrary(fHandle); {$endif} inherited; end; class function TSynLizardDynamic.AlgoRegister: boolean; var lib: TSynLizardDynamic; begin result := Lizard <> nil; if result then exit; // already registered (maybe as TSynLizardStatic) lib := TSynLizardDynamic.Create('', true); result := lib.Loaded; if result then Lizard := lib else lib.Free; end; initialization {$ifndef LIZARD_EXTERNALONLY} Lizard := TSynLizardStatic.Create; {$endif LIZARD_EXTERNALONLY} finalization Lizard.Free; {$endif LIZARD_STANDALONE} end.