Skip to content

[wasm] Expose Engine.clone to bindings #721

@ntnj

Description

@ntnj

While the Engine in wasm binding implements the Clone trait, it's not currently exposed in wasm binding, so there doesn't seem to be way to clone from Javascript.
A small clone method on Engine could be added to allow cloning in Javascript.

I was running a benchmark on Clone where I would clone before each evaluation, I noticed that without running a dummy evaluation first before cloning, each evaluation after cloning would be very slow.

I have to basically do (psuedocode)

template := new Engine()
engine.addPolicy(...)
engine.addDataJson(..)
engine.addInputJson(dummy)
engine.evalRule(dummy rule) // Without this evaluation, each eval after clone is very expensive.

for each loop {
  e := template.clone()
  e.addInputJson(...)
  e.evalRule(....)
}

To avoid using dummy inputs, can an API be provided in Rust, so we can call engine.prepare() after addDataJson.
I was using almost 1MB rego file.

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions