GithubHelp home page GithubHelp logo

cfc-servers / gm_lz4 Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 73 KB

LZ4 Binary for Garry's Mod with threaded options.

License: GNU General Public License v3.0

Lua 7.24% C++ 92.76%
garrysmod garrysmod-module gmod gmod-module gmod-modules

gm_lz4's Introduction

gm_lz4 ๐Ÿš€

Introducing gm_lz4, a high-performance Garry's Mod server-side module that provides a lightning-fast alternative to Garry's Mod's built-in util.Compress and util.Decompress functions, leveraging the power of the LZ4 compression algorithm.

It offers basic synchronous functions as well as asynchronous functions that run in a separate thread, preventing server freezes even when handling extremely large datasets.

Note: LZ4 is not compatible with LZMA, this module is an alternative for the base util functions, not a drop-in replacement (though I am working on an async LZMA module as well)

๐Ÿ“š Description

LZ4, a compression algorithm known for its "extremely fast decoding, with speed in multiple GB/s per core", outperforms Garry's Mod's default LZMA-powered util functions. While LZMA offers an excellent compression ratio, its sluggish performance makes working with large data in Garry's Mod a challenge.

LZ4 prioritizes speed over compression ratio. It's roughly 4-6x faster than Garry's Mod's LZMA, but produces a result that is approximately 30% larger.

โšก Benchmark

Input: 35.77 MB of JSON-ified table data

Method Avg. Time Ratio
util.Compress 6.912s 2.1:1
lz4.Compress 1.503s 1.4:1

Note: util.Compress in this case would cause the game and all players to freeze for almost seven full seconds if run server-side.

๐ŸŽฏ Use Cases

gm_lz4 excels in situations where speed takes precedence over compression ratio.

It's an ideal choice for addons that need to handle large amounts of data. Even for non-time-sensitive data, lz4.Compress may still be preferable as it doesn't lock up your server for long periods.

๐Ÿงฉ Asynchronous Functions

The gm_lz4 module, while already blazing fast, also provides asynchronous alternatives for both compressing and decompressing to ensure smooth server performance.

๐Ÿ› ๏ธ Usage

require( "lz4" )

local data = generateData()
local serialized = util.TableToJSON( data )

do
    local compressed = lz4.Compress( serialized )
    local decompressed = lz4.Decompress( compressed )
end

-- Async
lz4.CompressAsync( serialized, function( compressed )
    -- Now we have the compressed data, we can also decompress it asynchronously

    lz4.DecompressAsync( compressed, function( decompressed )
        assert( decompressed == serialized )
    end )
end )

gm_lz4's People

Contributors

brandonsturgeon avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

gm_lz4's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.