Skip to content

Compile and evaluate separately #30

Description

@markhats

I may be wrong, but it looks like when you call expression.evaluate({ x: 1 }), it compiles it into a JS function every time before evaluating. Is it possible to compile the expression just once and then call evaluate many times on the compiled function, passing in different values for x? This would make it much faster than compiling every time.

The equivalent math.js workflow would be:

const node = math.parse(expr)         // parse expression into a node tree
const code = node.compile()           // compile the node tree
const result = code.evaluate([scope]) // evaluate the code with an optional scope

where the final evaluate could be called multiple times without recompiling.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions