Navigation Menu

Skip to content

Commit

Permalink
perf: mimalloc as global allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Jun 10, 2021
1 parent 6473266 commit 3fbab59
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -12,6 +12,9 @@ napi = {version = "1", features = ["napi5"]}
napi-derive = "1"
snap = "1"

[target.'cfg(all(target_arch = "x86_64", not(target_env = "musl")))'.dependencies]
mimalloc = {version = "0.1"}

[build-dependencies]
napi-build = "1"

Expand Down
24 changes: 10 additions & 14 deletions README.md
Expand Up @@ -44,16 +44,12 @@ export function uncompress(compressed: Buffer): Promise<Buffer>
### Hardware

```
Model Name: MacBook Pro
Model Identifier: MacBookPro15,1
Processor Name: Intel Core i7
Processor Speed: 2.6 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
OS: Windows 10 x86_64
Host: Micro-Star International Co., Ltd. MS-7C35
Kernel: 10.0.19043
Terminal: Windows Terminal
CPU: AMD Ryzen 9 5950X (32) @ 3.400GHz
Memory: 15959MiB / 32688MiB
```
### Result
Expand All @@ -63,10 +59,10 @@ Running "Compress data" suite...
Progress: 100%

@napi-rs/snappy:
279 ops/s, ±7.86% | fastest
333 ops/s, ±2.10% | fastest

snappy node:
235 ops/s, ±1.85% | slowest, 15.77% slower
163 ops/s, ±1.44% | slowest, 51.05% slower

Finished 2 cases!
Fastest: @napi-rs/snappy
Expand All @@ -75,10 +71,10 @@ Running "Uncompress data" suite...
Progress: 100%

@napi-rs/snappy:
379 ops/s, ±2.09% | fastest
980 ops/s, ±1.85% | fastest

snappy node:
347 ops/s, ±1.93% | slowest, 8.44% slower
256 ops/s, ±0.61% | slowest, 73.88% slower

Finished 2 cases!
Fastest: @napi-rs/snappy
Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -6,6 +6,14 @@ extern crate napi_derive;
use napi::{CallContext, Env, Error, JsBuffer, JsBufferValue, JsObject, Ref, Result, Status, Task};
use snap::raw::{Decoder, Encoder};

#[cfg(all(
target_arch = "x86_64",
not(target_env = "musl"),
not(debug_assertions)
))]
#[global_allocator]
static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;

#[module_exports]
fn init(mut exports: JsObject) -> Result<()> {
exports.create_named_method("compressSync", compress_sync)?;
Expand Down

0 comments on commit 3fbab59

Please sign in to comment.