Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
287 changes: 98 additions & 189 deletions .github/workflows/CI.yaml

Large diffs are not rendered by default.

925 changes: 0 additions & 925 deletions .yarn/releases/yarn-4.5.0.cjs

This file was deleted.

942 changes: 942 additions & 0 deletions .yarn/releases/yarn-4.9.4.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.0.cjs
yarnPath: .yarn/releases/yarn-4.9.4.cjs
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ crate-type = ["cdylib"]

[dependencies]
lz4_flex = { version = "0.11.3" }
napi = "2"
napi-derive = "2"
napi = { version = "3.0.0", features = ["napi5", "serde-json"] }
napi-derive = { version = "3.0.0" }

[target.'cfg(all(any(windows, unix), target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
mimalloc = { version = "0.1" }
[target.'cfg(all(not(target_os = "linux"), not(target_family = "wasm")))'.dependencies]
mimalloc-safe = { version = "0.1", features = ["skip_collect_on_exit"] }

[target.'cfg(all(target_os = "linux", not(target_env = "ohos"), not(target_env = "musl")))'.dependencies]
mimalloc-safe = { version = "0.1", features = ["local_dynamic_tls", "skip_collect_on_exit"] }

[build-dependencies]
napi-build = "2.0.1"
Expand Down
63 changes: 45 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,39 @@ const uncompressedBuffer = await uncompress(compressedBuffer)
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array, dict?: string | Buffer) => Buffer
```
#### `compressFrameSync`

```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Buffer
```

#### `decompressFrameSync`

```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Buffer
```
#### `compressFrame`

```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Promise<Buffer>
```

#### `decompressFrame`

```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Promise<Buffer>
```


## Performance

### Hardware

Benchmarks runs on the following hardware:

- Processor Name: i9 9900K
- Total Number of Cores: 8
- Hyper-Threading Technology: Enabled
- Memory: 32 GB
- Processor Name: M4 pro
- Total Number of Cores: 12
- Memory: 24GB

### Benchmark

Expand All @@ -128,45 +150,50 @@ Running "Compress" suite...
Progress: 100%

lz4:
911 ops/s, ±18.64% | 54.68% slower
7 355 ops/s, ±1.73% | 0.39% slower

lz4 dict:
6 375 ops/s, ±0.29% | 13.66% slower

snappy:
2 010 ops/s, ±19.23% | fastest
7 384 ops/s, ±0.53% | fastest

gzip:
78 ops/s, ±18.76% | 96.12% slower
444 ops/s, ±0.50% | 93.99% slower

deflate:
118 ops/s, ±20.42% | 94.13% slower
442 ops/s, ±0.62% | 94.01% slower

brotli:
6 ops/s, ±0.21% | slowest, 99.7% slower
6 ops/s, ±0.73% | slowest, 99.92% slower

Finished 5 cases!
Finished 6 cases!
Fastest: snappy
Slowest: brotli
Running "Decompress" suite...
Progress: 100%

lz4:
9 425 ops/s, ±12.50% | fastest
19 095 ops/s, ±1.51% | fastest

lz4 dict:
17 644 ops/s, ±1.51% | 7.6% slower

snappy:
3 900 ops/s, ±13.39% | 58.62% slower
14 424 ops/s, ±0.50% | 24.46% slower

gzip:
823 ops/s, ±20.48% | slowest, 91.27% slower
2 442 ops/s, ±0.60% | 87.21% slower

deflate:
1 350 ops/s, ±12.52% | 85.68% slower
2 467 ops/s, ±0.61% | 87.08% slower

brotli:
979 ops/s, ±11.55% | 89.61% slower
1 659 ops/s, ±0.43% | slowest, 91.31% slower

Finished 5 cases!
Finished 6 cases!
Fastest: lz4
Slowest: gzip
Done in 61.20s.
Slowest: brotli
```

<!-- CONTRIBUTING -->
Expand Down
5 changes: 3 additions & 2 deletions benchmark/bench.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFileSync } from 'fs'
import { fileURLToPath } from 'node:url'
import { join } from 'path'
import { promisify } from 'util'
import {
Expand All @@ -25,8 +26,8 @@ const gunzipAsync = promisify(gunzip)
const inflateAsync = promisify(inflate)
const brotliDecompressAsync = promisify(brotliDecompress)

const FIXTURE = readFileSync(join(__dirname, '..', 'yarn.lock'))
const FIXTURE_DICT = readFileSync(join(__dirname, '..', '__test__/dict.bin'))
const FIXTURE = readFileSync(join(fileURLToPath(import.meta.url), '..', '..', 'yarn.lock'))
const FIXTURE_DICT = readFileSync(join(fileURLToPath(import.meta.url), '..', '..', '__test__/dict.bin'))
const LZ4_COMPRESSED_FIXTURE = Buffer.from(compressSync(FIXTURE))
const SNAPPY_COMPRESSED_FIXTURE = Buffer.from(snappy.compressSync(FIXTURE))
const GZIP_FIXTURE = gzipSync(FIXTURE)
Expand Down
23 changes: 12 additions & 11 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/* auto-generated by NAPI-RS */
/* eslint-disable */
export declare function compress(
data: string | Buffer,
dict?: string | Buffer | undefined | null,
): Promise<Buffer> | Promise<Buffer>
export declare function compressFrame(data: string | Buffer): Promise<Buffer>
export declare function compress(data: string | Uint8Array, dict?: string | Uint8Array | undefined | null): Promise<Buffer>

export declare function compressFrame(data: string | Uint8Array): Promise<Buffer>

export declare function compressFrameSync(data: string | Buffer): Buffer

export declare function compressSync(data: string | Buffer, dict?: string | Buffer | undefined | null): Buffer
export declare function decompressFrame(data: string | Buffer): Promise<Buffer>

export declare function decompressFrame(data: string | Uint8Array): Promise<Buffer>

export declare function decompressFrameSync(data: string | Buffer): Buffer
export declare function uncompress(
data: string | Buffer,
dict?: string | Buffer | undefined | null,
): Promise<Buffer> | Promise<Buffer>
export declare function uncompressSync(data: string | Buffer, dict?: string | Buffer | undefined | null): Buffer

export declare function uncompress(data: string | Uint8Array, dict?: string | Uint8Array | undefined | null): Promise<Buffer>

export declare function uncompressSync(data: string | Uint8Array, dict?: string | Uint8Array | undefined | null): Buffer
Loading
Loading