Giter Site home page Giter Site logo

experiment-evaluation's Introduction

experiment-evaluation

Multiplatform (JVM, Node.js, Native) implementation of the experiment evaluation engine. The purpose of this library is to share the same evaluation code across all local-evaluation experiment SDKs.

  • The current implementation supports:
  • JVM
  • Node.js
  • Native
    • macos
      • macosX64
      • macosArm64
    • linux
      • linuxX64
      • linuxArm64

Used in:

Build

This may take some time.

./gradlew assemble

Modules

evaluation-core

The core evaluation engine with public data types exposed. Used by other kotlin mulitplatform modules/libraries and JVM targets. This code is pure multiplatform kotlin, without any dependencies.

evaluation-interop

Module which supports better interoperability with native targets. Uses kotlinx serialization to serialize data across the native interface.

This module exposes a single function evaluate which takes JSON String inputs and outputs. The caller is in charge of building the json objects and parsing the result.

fun evaluate(rules: String, user: String): String

This kotlin function maps to an equivalent function in C:

const char* (*evaluate)(const char* rules, const char* user);

This string returned from the call to evaluate must be freed by calling the DisposeString utility function.

void (*DisposeString)(const char* string);

These functions are wrapped in structures generated by kotlin (some functions omitted):

typedef struct {
  /* Dispose string function. */
  void (*DisposeString)(const char* string);

  /* User functions. */
  struct {
    struct {
      /* Evaluate function. */
      const char* (*evaluate)(const char* rules, const char* user);
    } root;
  } kotlin;
} libevaluation_interop_ExportedSymbols;
extern libevaluation_interop_ExportedSymbols* libevaluation_interop_symbols(void);

Here's a full example of calling evaluate, then DisposeString in C:

#include "libevaluation_interop_api.h"
#include "stdio.h"

int main(int argc, char** argv) {
    libevaluation_interop_ExportedSymbols* lib = libevaluation_interop_symbols();

    const char* rules = "{}";
    const char* user = "{}";
    
    const char* response = lib->kotlin.root.evaluate(rules, user);
    printf("%s\n", response);
    lib->DisposeString(response);

    return 0;
}

Important Build Outputs

Native static and dynamic libraries are built for specific operating systems and architectures. For dynamic libraries, MacOS targets generate .dylib files while linux targets generate .so files. Outputs are generated for debug and release build flavors. Debug flavor outputs will contain additional debug info when the native code crashes (kotlin stack traces, register dump, etc).

  • <target>
    • macosX64: MacOS with Intel Chip
    • macosArm64: MacOS with M1 / Apple Silicon Chip
    • linuxX64: Linux with Intel/AMD (x64)
    • linuxArm64: Linux with Arm Chip
  • <flavor>
    • debug: larger, slower binaries with additional debug output on crash (stack traces, register dump, etc.)
    • release: smaller, faster binaries without additional debug output on crash.
  • <file>
    • dylib: output file type for macOS
    • so: output file type for linux
# Dynamic Libraries
build/bin/<target>/<flavor>Shared/libevaluation_interop.<file>
build/bin/<target>/<flavor>Shared/libevaluation_interop_api.h

# Static Libraries
build/bin/<target>/<flavor>Static/libevaluation_interop.a
build/bin/<target>/<flavor>Static/libevaluation_interop_api.h

evaluation-serialization

Module containing kotlinx serialization annotated objects and mapping functions for equivalent objects in evaluation-core. Core objects are not annotated in order to optimize JavaScript generated code size.

This module is used by evaluation-interop and experiment-jvm-server to add serialization to flag configs and user objects. This package is not supposed to be used externally.

evaluation-js

Module which only targets nodejs, optimizing bundle size and evaluation speed and consistency. The generated javascript is completely stateless, and takes and returns dynamic javascript objects/arrays in the evaluate function.

fun evaluate(rules: dynamic, user: dynamic): dynamic

experiment-evaluation's People

Contributors

amplitude-sdk-bot avatar bgiori avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.