Giter VIP home page Giter VIP logo

sqnappy's Introduction

Sqnappy

Squeak/Pharo binding for Snappy compression library. Sqnappy is using a VM plugin for calling Snappy C API. (It is not a pure Smalltalk implementation).

You can see these directories:

  • plugin-build
  • plugin build settings
  • plugin-binary
  • pre-built shared libraries (SnappyPlugin.dll, bundle, so, etc)
  • repository
  • Cypress style Smalltalk source tree

For MCZ packages, visit SmalltalkHub Sqnappy site.

Performance

Just a simple code snippet. But it would be helpful for showing Sqnappy's characteristics.

"## Test data ##"
originalBytes := Morph allSelectors asString asByteArray.
originalBytes size. "30363 bytes on my image"

"## Compressed size ##"
" GZipWriteStream "
originalBytes asString zipped size. "11036"
" Sqnappy"
(SnappyCore compress: originalBytes) size.  "17461 -- 1.6x bigger"

"## Round-trip time ##"
" GZipWriteStream/GZipReadStream "
[100 timesRepeat: [originalBytes asString zipped unzipped asByteArray]] timeToRun.  "487"
" Sqnappy "
[100 timesRepeat: [SnappyCore uncompress: (SnappyCore compress: originalBytes)]] timeToRun "45 -- 10.8x faster"

Features

  • Basic compress/uncompress API
  • Stream API with framing format support (interoperability was checked with snzip)
  • Custom stream format (.sqn - sqnappy)
    • Block size is changeable from 32k to 4M (default is 64k)
    • No CRC32C checking for speed
    • Data size is represented in big-endian

Usage

Basic:

"## Compress/Uncompress ##"
compressed := SnappyCore compress: data.
uncompressed := SnappyCore uncompress: compressed.

Streaming:

"## Streaming (write) ##"
wstrm := SnappyFraming sz writeStreamOn: ByteArray new.
wstrm nextPutAll: #[49 50 51 52 53 10 49 50 51 52 53 10].
wstrm nextPutAll: #[49 50 51 52 53 10 123 49 50 51 52 53 10 0].
compressed := wstrm contents.
wstrm close.
"## Streaming (read) ##"
rstrm := SnappyFraming sz readStreamOn: compressed.
uncompressed := rstrm contents.
rstrm close.
"## Streaming (partial read) ##"
rstrm := SnappyFraming sz readStreamOn: compressed.
[rstrm atEnd] whileFalse: [
  uncompressedPart := rstrm upTo: 10.
  Transcript cr; show: uncompressedPart asString
].
rstrm close.

Streaming with files: (This snippet is using FileMan for simplifying file access).

"## Compress 'SqueakV41.sources -> 'SqueakV41.sources.sqn' with Sqnappy format ##"
readStr := ('.' asDirectoryEntry / 'SqueakV41.sources') readStream binary.
writeEnt := '.' asDirectoryEntry / 'SqueakV41.sources.sqn'.
writer := SnappyFraming sqn writeStreamOn: writeEnt writeStream.
writer repeatWrite:[:w | w nextPutAll:(readStr next: w blockSize)] until:[readStr atEnd] finally:[:w | w close. readStr close].

"## Uncompress 'SqueakV41.sources.sqn -> 'SqueakV41.sources' ##"
readEnt := '.' asDirectoryEntry / 'SqueakV41.sources.sqn'.
reader := SnappyFraming sqn readStreamOn: readEnt readStream.
writeStr := ('.' asDirectoryEntry / 'SqueakV41-trip.sources') writeStream.
reader repeatReadUntilEnd:[:r | ] out: writeStr finally:[:r | r close. writeStr close].

On my windows laptop (Core-i5 2430M, Samsong SSD 840), Compressed file('SqueakV41.sources.sqn') was written in about 250 msecs. Uncompressed file('SqueakV41-trip.sources') was written in about 100 msecs. Original file size was 26,005,504 bytes. Compressed file size was 10,612,736 bytes.

Stream API enables you to handle pretty big data. I've also tested the code above with a big pg_dump file ( 1.3G - 1,304,485,888 bytes). There were no annoying GCs. Compressed size was 631,627,776 bytes. 9844 msecs for compress; 6496 msecs for uncompress.

Installation

  1. Copy the pre-built Snappy.dll (.so, .bundle) to your VM directory
  2. Load Sqnappy
"Squeak"
Installer squeaksource
    project: 'MetacelloRepository';
    install: 'ConfigurationOfSqnappy'. 
(Smalltalk at: #ConfigurationOfSqnappy) load.

"Pharo"
Gofer new
      url: 'http://smalltalkhub.com/mc/MasashiUmezawa/Sqnappy/main';
      package: 'ConfigurationOfSqnappy';
      load.
(Smalltalk at: #ConfigurationOfSqnappy) load.

Open TestRunner and see the results. If tests are red, please make sure step.1 was done properly.

Note: Plugin binaries were built for 32 bit Cog VM. For other VM (legacy VM, 64 bit VM, etc), probably you need to recompile plugin source by yourself.

License

MIT license

sqnappy's People

Contributors

mumez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kleopatra999

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.