Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4616592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:00:14+00:00 2026-05-22T02:00:14+00:00

I have a rules engine, which supports two modes of operations: Compilation into a

  • 0

I have a rules engine, which supports two modes of operations:

  1. Compilation into a C# program and linked into the engine
  2. Parsing into a reverse-polish stack-based instructions and interpreted

The rules are simple arithmetical expressions with function calls (max, min, sin, cos etc.)

I would have assumed the compiled version (i.e. #1) to be much faster than the interpreted version (i.e. #2) — in fact, that’s the main reason for having a compiled mode in the first place. However, my speed tests showed otherwise.

Compiled Version

Action<double>[] Rules = new[] { calc1, calc2, calc3 ... };
double[] v = new double[...];   // Variables

void calc1(double arg) { v[3]=v[12]+v[15]/v[20] };   // "x3=x12+x15/x20"
void calc2(double arg) { ... };
   :
// Start timer now
Rules.AsParallel().ForAll(r => r(...));
// End timer

Interpreted Version

Expression[] Rules = ...
// Each rule is already parsed into an Expression object, which is a set of
// reverse-polish stack-based instructions.
// For example, "x3=x12+x15/x20" will be parsed to:
//     [ Push(12), Push(15), Push(20), Divide(), Add() ]
// Start timer now
Rules.AsParallel().ForAll(r => r.Evaluate(...));
// End timer

Here, “Expression” is part of a third-party library that parses a simple string into a simple set of reverse-polish stack-based instructions, which can then be interpreted. It is not the expression-tree object in LINQ — just for clarification.

Note: don’t worry about concurrency since in the real code, I sort the rules by “layers” and calculate the layers sequentially, which each layer only depending on values calculated in previous layers. Both modes have the exact same layers structure.

The Results

Shockingly, the interpreted version runs MUCH faster than the compiled version, average a factor of 4x! In other words, the compiled version took 0.3s to run through around 1,200 rules, while the interpreted version took on average 0.08-0.1s.

My computer is a so-so dual-core Core2.

I am using .NET 4.0, Visual Studio 10.

Performance is similar in Debug or Release builds.

My Question

What can be causing the significant slowdown in the compiled mode?

NOTE: I HAVE POSTED ONE POSSIBLE ANSWER

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:00:15+00:00Added an answer on May 22, 2026 at 2:00 am

    .NET is a JIT-compiled environment, so the more code to JIT-compile, the slower it is. It can be that 1,200 methods are JIT-compiled at run-time at the point of execution, vs. in the interpreted mode only the interpreter is JIT-compiled, once. I may be seeing extra JIT times in my loops for the compiled mode.

    Experiment:

    1. Run each mode 5 times (just to complete any JIT compilation and fill caches)
    2. Time 50 runs, take the average

    Results:

    1. Compiled mode: 1.6ms per run
    2. Interpreted mode: 5.3ms per run

    Observations:

    It appears that a large amount of time is spent during the FIRST run of the compiled mode.

    The SECOND run of the compiled mode is already similar in speed to the interpreted mode.

    The interpreted mode does not speed up significant with the number of runs.

    Thus suggesting my point of view that the rule code is JIT-compiled during the first run.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my site I have mod_rewrite rules to make the URLs more search engine
I have seen various rules for naming stored procedures. Some people prefix the sproc
Do you have any advice/rules on selecting a multiplier to use in a (multiplicative)
Rules like A parent object will have up to 2 children could be enforced
I have a few problems with my mod_rewrite rules. There a three different url
I have a strange problem with mod_rewrite, the rules that are relevant here are:
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
Do you know any documentation about the rules of using update sites? I have
What exactly are the Python scoping rules? If I have some code: code1 class
I just finished reading this post: https://developer.yahoo.com/performance/rules.html#flush and have already implemented a flush after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.