Skip to content

Commit c795ab3

Browse files
authored
Merge pull request #3 from Brooooooklyn/jieba
feat(jieba): impl jieba-rs binding
2 parents f298cd3 + 9676a43 commit c795ab3

File tree

25 files changed

+793
-35
lines changed

25 files changed

+793
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ jobs:
9090
if: matrix.os == 'ubuntu-latest'
9191

9292
- name: Run build
93-
run: npx lerna run build --stream -- --platform
93+
run: |
94+
cargo build --release
95+
npx lerna run build --stream -- --platform
9496
9597
- name: Upload artifact
9698
uses: actions/upload-artifact@v2
@@ -196,6 +198,7 @@ jobs:
196198
shell: bash
197199
- name: Lerna publish
198200
run: |
201+
find ./packages/ -type d -maxdepth 1 -exec cp LICENSE {} \;
199202
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
200203
npx lerna publish from-package --no-verify-access --yes
201204
env:

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
22
members = [
3-
"./packages/crc32"
3+
"./packages/crc32",
4+
"./packages/jieba"
45
]
File renamed without changes.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Make rust crates binding to NodeJS use [napi-rs](https://github.com/Brooooooklyn
1616

1717
# Packages
1818

19-
| Package | Status | Description |
20-
| ---------------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------- |
21-
| [`@node-rs/crc32`](./packages/crc32/README.md) | ![](https://github.com/Brooooooklyn/node-rs/workflows/CI/badge.svg) | Fastest `CRC32` implementation using `SIMD` |
19+
| Package | Status | Description |
20+
| ---------------------------------------------- | ------------------------------------------------------------------- | ---------------------------------------------------------- |
21+
| [`@node-rs/crc32`](./packages/crc32/README.md) | ![](https://github.com/Brooooooklyn/node-rs/workflows/CI/badge.svg) | Fastest `CRC32` implementation using `SIMD` |
22+
| [`@node-rs/jieba`](./packages/jieba/README,md) | ![](https://github.com/Brooooooklyn/node-rs/workflows/CI/badge.svg) | [`jieba-rs`](https://github.com/messense/jieba-rs) binding |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"private": true,
99
"workspaces": ["packages/*"],
1010
"scripts": {
11-
"bench": "lerna run bench --stream --no-prefix",
11+
"bench": "lerna run bench --concurrency 1 --stream --no-prefix",
1212
"build:ts": "tsc -b tsconfig.project.json -verbose",
1313
"lint": "eslint . -c ./.eslintrc.yml 'packages/**/*.{ts,js}'",
1414
"test": "ava",

packages/crc32/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ napi-rs = { version = "0.2" }
1212
napi-rs-derive = { version = "0.1" }
1313
crc32fast = "1.2"
1414

15+
[target.'cfg(unix)'.dependencies]
16+
jemallocator = { version = "0.3", features = ["disable_initial_exec_tls"] }
17+
1518
[build-dependencies]
1619
napi-build = { version = "0.1" }

packages/crc32/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ The 4 tested implementations are:
1111
- **js_crc32c** Javascript implemented CRC-32C
1212
- **js_crc32** Javascript implemented CRC-32 from [buffer-crc32](https://github.com/brianloveswords/buffer-crc32)
1313

14-
# Performance
14+
## Performance
1515

1616
```bash
17-
sse4_crc32c_node_rs for inputs 1024B x 5,108,123 ops/sec ±1.86% (89 runs sampled)
18-
sse4_crc32c_node_rs for inputs 16931844B, avg 2066B x 271 ops/sec ±1.15% (85 runs sampled)
17+
@node-rs/crc32 for inputs 1024B x 5,108,123 ops/sec ±1.86% (89 runs sampled)
18+
@node-rs/crc32 for inputs 16931844B, avg 2066B x 271 ops/sec ±1.15% (85 runs sampled)
1919
sse4_crc32c_hw for inputs 1024B x 3,543,443 ops/sec ±1.39% (93 runs sampled)
2020
sse4_crc32c_hw for inputs 16931844B, avg 2066B x 209 ops/sec ±0.78% (76 runs sampled)
2121
sse4_crc32c_sw for inputs 1024B x 1,460,284 ops/sec ±2.35% (90 runs sampled)
@@ -27,7 +27,7 @@ js_crc32 for inputs 16931844B, avg 2066B x 22.12 ops/sec ±5.20% (40 runs sample
2727
+---------------------+-------------------+----------------------+
2828
| │ 1024B │ 16931844B, avg 2066B |
2929
+---------------------+-------------------+----------------------+
30-
| sse4_crc32c_node_rs │ 5,108,123 ops/sec │ 271 ops/sec |
30+
| @node-rs/crc32 │ 5,108,123 ops/sec │ 271 ops/sec |
3131
+---------------------+-------------------+----------------------+
3232
| sse4_crc32c_hw │ 3,543,443 ops/sec │ 209 ops/sec |
3333
+---------------------+-------------------+----------------------+
@@ -39,13 +39,13 @@ js_crc32 for inputs 16931844B, avg 2066B x 22.12 ops/sec ±5.20% (40 runs sample
3939
+---------------------+-------------------+----------------------+
4040
```
4141

42-
# Support matrix
42+
## Support matrix
4343

4444
| | node 10 | node12 | node13 | node14 |
4545
| ----------------- | ------- | ------ | ------ | ------ |
46-
| Windows 64 latest | | | | |
47-
| macOS latest | | | | |
48-
| Linux | | | | |
46+
| Windows 64 latest | | | | |
47+
| macOS latest | | | | |
48+
| Linux | | | | |
4949

5050
## API
5151

packages/crc32/benchmark/crc32.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ egestas tempus leo. Duis condimentum turpis duis.`)
2323
const initialCrc32 = crc32Node(TEST_BUFFER)
2424
const initialCrc32c = Sse4Crc32.calculate(TEST_BUFFER)
2525

26-
console.assert(crc32(TEST_BUFFER), initialCrc32)
27-
console.assert(crc32c(TEST_BUFFER), initialCrc32c)
26+
console.assert(crc32(TEST_BUFFER) === initialCrc32)
27+
console.assert(crc32c(TEST_BUFFER) === initialCrc32c)
2828

2929
const suite = new Suite('crc32c without initial crc')
3030

3131
suite
32-
.add('SIMD + NAPI', () => {
32+
.add('@node/rs crc32c', () => {
3333
crc32c(TEST_BUFFER)
3434
})
3535
.add('sse4_crc32', () => {
@@ -46,7 +46,7 @@ suite
4646
const suite2 = new Suite('crc32c with initial crc')
4747

4848
suite2
49-
.add('SIMD + NAPI', () => {
49+
.add('@node/rs crc32c', () => {
5050
crc32c(TEST_BUFFER, initialCrc32c)
5151
})
5252
.add('sse4_crc32', () => {
@@ -63,7 +63,7 @@ suite2
6363
const suite3 = new Suite('crc32 without initial crc')
6464

6565
suite3
66-
.add('SIMD + NAPI', () => {
66+
.add('@node/rs crc32', () => {
6767
crc32(TEST_BUFFER)
6868
})
6969
.add('Node crc', () => {
@@ -80,7 +80,7 @@ suite3
8080
const suite4 = new Suite('crc32 with initial crc')
8181

8282
suite4
83-
.add('SIMD + NAPI', () => {
83+
.add('@node/rs crc32', () => {
8484
crc32(TEST_BUFFER, initialCrc32)
8585
})
8686
.add('Node crc32', () => {

packages/crc32/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
},
2020
"scripts": {
2121
"bench": "cross-env NODE_ENV=production node benchmark/crc32.js",
22-
"build": "cargo build --release && napi --release ./crc32",
23-
"build:debug": "cargo build && napi ./index"
22+
"build": "napi --release ./crc32",
23+
"build:debug": "napi ./index"
2424
},
2525
"bugs": {
2626
"url": "https://github.com/Brooooooklyn/node-rs/issues"

packages/crc32/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use crc32fast::Hasher;
88
use napi::{Buffer, CallContext, Env, Number, Object, Result, Value};
99
use std::convert::TryInto;
1010

11+
#[cfg(unix)]
12+
#[global_allocator]
13+
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
14+
1115
mod bytes;
1216
mod crc32;
1317
mod crc32_table;
@@ -24,7 +28,7 @@ fn init<'env>(
2428
}
2529

2630
#[js_function(2)]
27-
fn crc32c<'a>(ctx: CallContext<'a>) -> Result<Value<'a, Number>> {
31+
fn crc32c(ctx: CallContext) -> Result<Value<Number>> {
2832
let input_data = ctx.get::<Buffer>(0)?;
2933
let init_state = ctx.get::<Number>(1);
3034
let result = if init_state.is_ok() {
@@ -36,7 +40,7 @@ fn crc32c<'a>(ctx: CallContext<'a>) -> Result<Value<'a, Number>> {
3640
}
3741

3842
#[js_function(2)]
39-
fn crc32<'a>(ctx: CallContext<'a>) -> Result<Value<'a, Number>> {
43+
fn crc32(ctx: CallContext) -> Result<Value<Number>> {
4044
let input_data = ctx.get::<Buffer>(0)?;
4145
let init_state = ctx.get::<Number>(1);
4246
let mut hasher = if init_state.is_ok() {

0 commit comments

Comments
 (0)