Skip to content

Commit

Permalink
Merge pull request #36 from Brooooooklyn/fix-buffer-perf
Browse files Browse the repository at this point in the history
fix: avoid copy input buffer
  • Loading branch information
Brooooooklyn committed Oct 27, 2021
2 parents 0dd85aa + 00cdd39 commit f37f9c6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 40 deletions.
94 changes: 58 additions & 36 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ jobs:
settings:
- host: macos-latest
target: 'x86_64-apple-darwin'
build: yarn build
build: |
yarn build
strip -x *.node
- host: windows-latest
build: yarn build
target: 'x86_64-pc-windows-msvc'
Expand Down Expand Up @@ -55,17 +57,21 @@ jobs:
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip snappy.linux-x64-musl.node
- host: macos-latest
target: 'aarch64-apple-darwin'
build: yarn build --target=aarch64-apple-darwin
build: |
yarn build --target=aarch64-apple-darwin
strip -x *.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-gnu'
setup: |
sudo apt-get update
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y
build: |
yarn build --target=aarch64-unknown-linux-gnu
aarch64-linux-gnu-strip snappy.linux-arm64-gnu.node
- host: ubuntu-latest
target: 'armv7-unknown-linux-gnueabihf'
setup: |
sudo apt-get update
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
yarn build --target=armv7-unknown-linux-gnueabihf
Expand All @@ -75,6 +81,7 @@ jobs:
build: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
yarn build --target aarch64-linux-android
${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip *.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl'
Expand Down Expand Up @@ -196,6 +203,7 @@ jobs:
freebsd-version
yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
yarn build
strip -x snappy.freebsd-x64.node
yarn test
yarn test:mem
rm -rf node_modules
Expand Down Expand Up @@ -368,21 +376,24 @@ jobs:
run: ls -R .
shell: bash

- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-linux-aarch64-gnu-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000

- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:arm64-focal
uses: addnab/docker-run-action@v3
with:
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn test && \
yarn test:mem && \
ls -la
"
image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
options: '-v ${{ github.workspace }}:/build -w /build'
run: |
yarn test
ls -la
test-linux-aarch64-musl-binding:
name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }}
needs:
Expand All @@ -405,16 +416,24 @@ jobs:
run: ls -R .
shell: bash

- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-linux-aarch64-musl-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000

- name: Setup and run tests
uses: docker://multiarch/alpine:aarch64-latest-stable
uses: addnab/docker-run-action@v3
with:
args: >
sh -c "
apk add nodejs npm && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
npm test
"
image: multiarch/alpine:aarch64-latest-stable
options: '-v ${{ github.workspace }}:/build -w /build'
run: |
apk add nodejs npm yarn
yarn test
test-linux-arm-gnueabihf-binding:
name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }}
needs:
Expand All @@ -440,21 +459,24 @@ jobs:
run: ls -R .
shell: bash

- name: Cache NPM dependencies
uses: actions/cache@v2
with:
path: node_modules
key: npm-cache-test-linux-arm-gnueabihf-${{ matrix.node }}-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000

- name: Setup and run tests
uses: docker://multiarch/ubuntu-core:armhf-focal
uses: addnab/docker-run-action@v3
with:
args: >
sh -c "
apt-get update && \
apt-get install -y ca-certificates gnupg2 curl apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
apt-get install -y nodejs && \
npm install -g yarn && \
yarn install --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 && \
yarn test && \
yarn test:mem && \
ls -la
"
image: ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}
options: '-v ${{ github.workspace }}:/build -w /build'
run: |
yarn test
ls -la
publish:
name: Publish
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
authors = ["LongYinan <lynweklm@gmail.com>"]
edition = "2018"
edition = "2021"
name = "napi-snappy"
version = "0.1.0"

Expand All @@ -19,4 +19,5 @@ mimalloc = {version = "0.1"}
napi-build = "1"

[profile.release]
codgen-units = 1
lto = true
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const {
} = loadBinding(__dirname, 'snappy', '@napi-rs/snappy')

module.exports.compress = function compress(input) {
return _compress(Buffer.from(input))
return _compress(Buffer.isBuffer(input) ? input : Buffer.from(input))
}

module.exports.compressSync = function compressSync(input) {
return _compressSync(Buffer.from(input))
return _compressSync(Buffer.isBuffer(input) ? input : Buffer.from(input))
}

module.exports.compress = function compress(input) {
return _compress(Buffer.from(input))
return _compress(Buffer.isBuffer(input) ? input : Buffer.from(input))
}

module.exports.uncompress = function uncompress(input, opt = { asBuffer: true }) {
Expand Down

0 comments on commit f37f9c6

Please sign in to comment.