Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java/chore benchmarks #78

Draft
wants to merge 11 commits into
base: chore/benchmarks
Choose a base branch
from
Draft
66 changes: 66 additions & 0 deletions .github/workflows/build-dotnet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
name: .NET Build

on:
push:
branches:
- main
paths:
- 'dotnet-engine/**'
pull_request:
branches:
- main
paths:
- 'dotnet-engine/**'

jobs:
build-dotnet:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v3

## snatched from build-java.yml
## begin build yggdrasil (maybe this can be a separate job)
- name: Install rust
run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile default
rustup show
- name: Rust cache
uses: Swatinem/rust-cache@v2
- name: Build yggdrasil
run: cargo build --release
## end build yggdrasil

## snatched from build-java.yml
## Test requirements
- name: Get client spec
uses: actions/checkout@v3
with:
repository: Unleash/client-specification
ref: v5.0.2
path: client-specification

- name: Set up .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

- name: Restore dependencies
run: |
cd dotnet-engine
dotnet restore dotnet-engine.sln

- name: Build
run: dotnet build dotnet-engine.sln --configuration Release --no-restore

- name: Test
run: |
cd Yggdrasil.Engine.Tests
dotnet test --no-restore

34 changes: 34 additions & 0 deletions .github/workflows/build-wasm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build and Publish WASM

on:
push:
branches:
- main
paths:
- 'wasm-engine/**'
tags:
- '*'
workflow_dispatch:
inputs:
version:
description: 'Version (for manual trigger)'
required: true

jobs:
build-and-publish-wasm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install wasm-pack
uses: jetli/[email protected]

- name: Build WASM
run: wasm-pack build --target nodejs
File renamed without changes.
19 changes: 19 additions & 0 deletions dotnet-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ dotnet build
dotnet test
```

## Development

You can publish local packages to test with your SDK like this:

```bash
dotnet build
dotnet pack /p:Version=1.0.0-alpha.0
cd bin/Debug
dotnet nuget push "*.nupkg" -s ~/path/to/local/feed
```

Then add that local folder as a feed in NuGet

```bash
dotnet nuget add source ~/path/to/local/feed
```

Now you can switch package source in package manager and import your locally published package to work with.

## Running the benchmarks

```bash
Expand Down
50 changes: 50 additions & 0 deletions dotnet-engine/README.md.orig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# CSharp Bindings for Yggdrasil

## Build

Build the base project with cargo:

```bash
cargo build --release
```

Csharp doesn't require the library path so this should work:

```bash
dotnet build
```

## Running the tests

```bash
dotnet test
```

<<<<<<< HEAD
## Running the benchmarks

```bash
dotnet run --project Yggdrasil.Benchmarks -c Release
```

Output can be read in Yggdrasil.Benchmarks/BenchmarkDotNet.Artifacts/results
=======
## Development

You can publish local packages to test with your SDK like this:

```bash
dotnet build
dotnet pack /p:Version=1.0.0-alpha.0
cd bin/Debug
dotnet nuget push "*.nupkg" -s ~/path/to/local/feed
```

Then add that local folder as a feed in NuGet

```bash
dotnet nuget add source ~/path/to/local/feed
```

Now you can switch package source in package manager and import your locally published package to work with.
>>>>>>> origin/main
64 changes: 63 additions & 1 deletion dotnet-engine/Yggdrasil.Engine.Tests/YggdrasilEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NUnit.Framework;
using System;
using Newtonsoft.Json.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Yggdrasil;


Expand Down Expand Up @@ -101,4 +100,67 @@ public void TestClientSpec()
}
}

[Test]
public void Impression_Data_Test_Enabled() {
var testDataObject = new {
Version = 2,
Features = new [] {
new {
Name = "with.impression.data",
Type = "release",
Enabled = true,
ImpressionData = true,
Strategies = new [] {
new {
Name = "default",
Parameters = new Dictionary<string, string>()
}
}
}
}
};

var testData = JsonSerializer.Serialize(testDataObject, options);
var engine = new YggdrasilEngine();
engine.TakeState(testData);
var featureName = "with.impression.data";
var result = engine.IsEnabled(featureName, new Context());
var shouldEmit = engine.ShouldEmitImpressionEvent(featureName);
Assert.NotNull(result);
Assert.IsTrue(result);
Assert.NotNull(shouldEmit);
Assert.IsTrue(shouldEmit);
}

[Test]
public void Impression_Data_Test_Disabled() {
var testDataObject = new {
Version = 2,
Features = new [] {
new {
Name = "with.impression.data.false",
Type = "release",
Enabled = true,
ImpressionData = false,
Strategies = new [] {
new {
Name = "default",
Parameters = new Dictionary<string, string>()
}
}
}
}
};

var testData = JsonSerializer.Serialize(testDataObject, options);
var engine = new YggdrasilEngine();
engine.TakeState(testData);
var featureName = "with.impression.data.false";
var result = engine.IsEnabled(featureName, new Context());
var shouldEmit = engine.ShouldEmitImpressionEvent(featureName);
Assert.NotNull(result);
Assert.IsTrue(result);
Assert.NotNull(shouldEmit);
Assert.IsFalse(shouldEmit);
}
}
11 changes: 11 additions & 0 deletions dotnet-engine/Yggdrasil.Engine/FFI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ string customStrategyResults
private delegate void FreeResponseDelegate(IntPtr ptr);
private delegate void CountToggleDelegate(IntPtr ptr, string toggle_name, bool enabled);
private delegate void CountVariantDelegate(IntPtr ptr, string toggle_name, string variant_name);
private delegate bool ShouldEmitImpressionEventDelegate(IntPtr ptr, string toggle_name);

private static readonly NewEngineDelegate _newEngine;
private static readonly FreeEngineDelegate _freeEngine;
Expand All @@ -34,6 +35,7 @@ string customStrategyResults
private static readonly FreeResponseDelegate _free_response;
private static readonly CountToggleDelegate _count_toggle;
private static readonly CountVariantDelegate _count_variant;
private static readonly ShouldEmitImpressionEventDelegate _should_emit_impression_event;

static FFI()
{
Expand Down Expand Up @@ -75,6 +77,10 @@ static FFI()
_count_variant = Marshal.GetDelegateForFunctionPointer<CountVariantDelegate>(
NativeLibrary.GetExport(libHandle, "count_variant")
);

_should_emit_impression_event = Marshal.GetDelegateForFunctionPointer<ShouldEmitImpressionEventDelegate>(
NativeLibrary.GetExport(libHandle, "should_emit_impression_event")
);
}

private static string GetLibraryPath()
Expand Down Expand Up @@ -149,4 +155,9 @@ public static void CountVariant(IntPtr ptr, string toggle_name, string variant_n
{
_count_variant(ptr, toggle_name, variant_name);
}

public static bool ShouldEmitImpressionEvent(IntPtr ptr, string toggle_name)
{
return _should_emit_impression_event(ptr, toggle_name);
}
}
9 changes: 9 additions & 0 deletions dotnet-engine/Yggdrasil.Engine/Yggdrasil.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>Yggdrasil.Engine</PackageId>
<Version>1.0.0-beta.0</Version>
<Company>Bricks Software AS</Company>
<Authors>Unleash</Authors>
<IncludeSymbols>True</IncludeSymbols>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<Content Include="../../target/release/libyggdrasilffi.so" Condition="Exists('../../target/release/libyggdrasilffi.so')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<Content Include="../../target/release/libyggdrasilffi.dylib" Condition="Exists('../../target/release/libyggdrasilffi.dylib')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
<Content Include="../../target/release/libyggdrasilffi.dll" Condition="Exists('../../target/release/libyggdrasilffi.dll')">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions dotnet-engine/Yggdrasil.Engine/YggdrasilEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public YggdrasilEngine()
state = FFI.NewEngine();
}

public bool ShouldEmitImpressionEvent(string featureName)
{
return FFI.ShouldEmitImpressionEvent(state, featureName);
}

public void Dispose()
{
FFI.FreeEngine(this.state);
Expand Down
6 changes: 3 additions & 3 deletions java-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ dependencies {

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.14.2'

jmh 'org.openjdk.jmh:jmh-core:1.33'
jmh 'org.openjdk.jmh:jmh-core:1.35'

jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.33'
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.35'
}

// Apply a specific Java toolchain to ease working on different environments.
Expand All @@ -42,7 +42,7 @@ tasks.named('test') {
}

jmh {
version = '1.33'
version = '1.35'
fork = 2
includeTests = false
iterations = 5
Expand Down
Loading