Skip to content

Commit

Permalink
feat: improve switch performance (#159)
Browse files Browse the repository at this point in the history
* fix: improve switch performance

* fix pipeline
  • Loading branch information
stefan-gorules authored May 13, 2024
1 parent d0ec9a1 commit 2d1beba
Show file tree
Hide file tree
Showing 11 changed files with 2,170 additions and 115 deletions.
142 changes: 72 additions & 70 deletions .github/workflows/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ jobs:
build: |
yarn lerna exec "yarn build --target x86_64-pc-windows-msvc" --concurrency 1 --stream --no-prefix
- host: macos-latest
- host: macos-13
target: 'x86_64-apple-darwin'
build: |
rustup target add x86_64-apple-darwin
yarn lerna exec "yarn build --target x86_64-apple-darwin" --concurrency 1 --stream --no-prefix
strip -x ./*.node
- host: macos-latest
- host: macos-14
target: 'aarch64-apple-darwin'
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
Expand Down Expand Up @@ -80,17 +80,17 @@ jobs:
yarn lerna exec "yarn build --target aarch64-unknown-linux-gnu" --concurrency 1 --stream --no-prefix
llvm-strip ./*.node
# - host: ubuntu-latest
# target: 'x86_64-unknown-linux-musl'
# build: |
# cd bindings/nodejs &&
# yarn build
# - host: ubuntu-latest
# target: 'aarch64-unknown-linux-musl'
# build: >-
# set -e &&
# rustup target add aarch64-unknown-linux-musl &&
# yarn lerna exec "yarn build --target aarch64-unknown-linux-musl" --concurrency 1 --stream --no-prefix
# - host: ubuntu-latest
# target: 'x86_64-unknown-linux-musl'
# build: |
# cd bindings/nodejs &&
# yarn build
# - host: ubuntu-latest
# target: 'aarch64-unknown-linux-musl'
# build: >-
# set -e &&
# rustup target add aarch64-unknown-linux-musl &&
# yarn lerna exec "yarn build --target aarch64-unknown-linux-musl" --concurrency 1 --stream --no-prefix

name: stable - ${{ matrix.settings.target }} - node@18
runs-on: ${{ matrix.settings.host }}
Expand Down Expand Up @@ -166,11 +166,13 @@ jobs:
fail-fast: false
matrix:
settings:
- host: macos-latest
- host: macos-13
target: 'x86_64-apple-darwin'
- host: macos-14
target: 'aarch64-apple-darwin'
- host: windows-latest
target: 'x86_64-pc-windows-msvc'
node: ['16', '18', '20']
node: [ '16', '18', '20' ]
runs-on: ${{ matrix.settings.host }}

steps:
Expand Down Expand Up @@ -214,7 +216,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['16', '18', '20']
node: [ '16', '18', '20' ]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -293,57 +295,57 @@ jobs:
run: |
yarn lerna link
yarn test
# test-linux-aarch64-gnu-binding:
# name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
# needs:
# - build
# defaults:
# run:
# working-directory: ${{ env.WORKING_DIRECTORY }}
# strategy:
# fail-fast: false
# matrix:
# node: ['14', '16', '18']
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
# - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
# - name: List directory
# run: |
# ls -la &&
# pwd
#
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: bindings-aarch64-unknown-linux-gnu
# path: artifacts
#
# - name: Install dependencies
# run: |
# yarn config set supportedArchitectures.cpu "arm64"
# yarn config set supportedArchitectures.libc "glibc"
# yarn install --immutable --mode=skip-build
# - name: Move artifacts
# run: yarn artifacts
# shell: bash
#
# - name: List folder
# run: ls ./
# shell: bash
#
# - name: Setup and run tests
# uses: addnab/docker-run-action@v3
# with:
# image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
# options: -v ${{ github.workspace }}:/workspace -w /workspace
# run: |
# ls -la
# cd bindings/nodejs
# yarn install
# yarn link
# yarn test
# test-linux-aarch64-gnu-binding:
# name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
# needs:
# - build
# defaults:
# run:
# working-directory: ${{ env.WORKING_DIRECTORY }}
# strategy:
# fail-fast: false
# matrix:
# node: ['14', '16', '18']
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
# - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
# - name: List directory
# run: |
# ls -la &&
# pwd
#
# - name: Download artifacts
# uses: actions/download-artifact@v3
# with:
# name: bindings-aarch64-unknown-linux-gnu
# path: artifacts
#
# - name: Install dependencies
# run: |
# yarn config set supportedArchitectures.cpu "arm64"
# yarn config set supportedArchitectures.libc "glibc"
# yarn install --immutable --mode=skip-build
# - name: Move artifacts
# run: yarn artifacts
# shell: bash
#
# - name: List folder
# run: ls ./
# shell: bash
#
# - name: Setup and run tests
# uses: addnab/docker-run-action@v3
# with:
# image: ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}
# options: -v ${{ github.workspace }}:/workspace -w /workspace
# run: |
# ls -la
# cd bindings/nodejs
# yarn install
# yarn link
# yarn test

release:
name: Release
Expand All @@ -354,9 +356,9 @@ jobs:
needs:
- test-linux-x64-gnu-binding
- test-linux-x64-centos-7
# - test-linux-x64-musl-binding
# - test-linux-aarch64-gnu-binding
# - test-linux-arm-gnueabihf-binding
# - test-linux-x64-musl-binding
# - test-linux-aarch64-gnu-binding
# - test-linux-arm-gnueabihf-binding
- test-macOS-windows-binding
steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion bindings/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.node
*.node
*.internal.js
4 changes: 4 additions & 0 deletions bindings/nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

/* auto-generated by NAPI-RS */

export interface ZenConfig {
nodesInContext?: boolean
}
export function overrideConfig(config: ZenConfig): void
export interface ZenEvaluateOptions {
maxDepth?: number
trace?: boolean
Expand Down
3 changes: 2 additions & 1 deletion bindings/nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { ZenDecisionContent, ZenDecision, ZenEngine, evaluateExpressionSync, evaluateUnaryExpressionSync, renderTemplateSync, evaluateExpression, evaluateUnaryExpression, renderTemplate, ZenEngineHandlerRequest } = nativeBinding
const { overrideConfig, ZenDecisionContent, ZenDecision, ZenEngine, evaluateExpressionSync, evaluateUnaryExpressionSync, renderTemplateSync, evaluateExpression, evaluateUnaryExpression, renderTemplate, ZenEngineHandlerRequest } = nativeBinding

module.exports.overrideConfig = overrideConfig
module.exports.ZenDecisionContent = ZenDecisionContent
module.exports.ZenDecision = ZenDecision
module.exports.ZenEngine = ZenEngine
Expand Down
16 changes: 16 additions & 0 deletions bindings/nodejs/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use napi_derive::napi;
use std::sync::atomic::Ordering;
use zen_engine::ZEN_CONFIG;

#[napi(object)]
pub struct ZenConfig {
pub nodes_in_context: Option<bool>,
}

#[allow(dead_code)]
#[napi]
pub fn override_config(config: ZenConfig) {
if let Some(val) = config.nodes_in_context {
ZEN_CONFIG.nodes_in_context.store(val, Ordering::Relaxed)
}
}
1 change: 1 addition & 0 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod config;
mod content;
mod custom_node;
mod decision;
Expand Down
17 changes: 17 additions & 0 deletions core/engine/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use once_cell::sync::Lazy;
use std::sync::atomic::AtomicBool;

#[derive(Debug)]
pub struct ZenConfig {
pub nodes_in_context: AtomicBool,
}

impl Default for ZenConfig {
fn default() -> Self {
Self {
nodes_in_context: AtomicBool::new(true),
}
}
}

pub static ZEN_CONFIG: Lazy<ZenConfig> = Lazy::new(|| Default::default());
Loading

0 comments on commit 2d1beba

Please sign in to comment.