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 1029659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:34:45+00:00 2026-05-16T12:34:45+00:00

I am interested in some optimization methods or general bytecode designs, which might help

  • 0

I am interested in some optimization methods or general bytecode designs, which might help speed up execution using VM in comparison to interpretation of an AST.

  • 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-16T12:34:46+00:00Added an answer on May 16, 2026 at 12:34 pm

    The main win in AST interpretation vs. bytecode is operation dispatch cost, for highly optimised interpreters this starts to become a real problem. “Dispatch” is the term used to describe the overhead required to start executing an operation (such as arithmetic, property access, etc).

    A fairly normal AST based interpreter would look something like this:

    class ASTNode {
        virtual double execute() = 0;
    }
    
    class NumberNode {
        virtual double execute() { return m_value; }
        double m_value;
    }
    
    class AddNode {
        virtual double execute() { return left->execute() + right->execute(); }
    }
    

    So executing the code for something as simple as 1+1 requires 3 virtual calls. Virtual calls a very expensive (in the grand scheme of things) due to the multiple indirections to make the call, and the general cost of making a call in the first place.

    In a bytecode interpreter you have you a different dispatch model — rather than virtual calls you have an execution loop, akin to:

    while (1) {
        switch (op.type) {
            case op_add:
                // Efficient interpreters use "registers" rather than
                // a stack these days, but the example code would be more
                // complicated
                push(pop() + pop());
                continue;
            case op_end:
                return pop();
        }
    }
    

    This still has a reasonably expensive dispatch cost vs native code, but is much faster than virtual dispatch. You can further improve perf using a gcc extension called “computed goto” which allows you to remove the switch dispatch, reducing total dispatch cost to basically a single indirect branch.

    In addition to improving dispatch costs bytecode based interpreters have a number of additional advantages over AST interpreters, mostly due to the ability of the bytecode to “directly” jump to other locations as a real machine would, for example imagine a snippet of code like this:

    while (1) {
        ...statements...
        if (a)
            break;
        else
            continue;
    }
    

    To implement this correctly everytime a statement is executed you would need to indicate whether execution is meant to stay in the loop or stop, so the execution loop becomes something like:

    while (condition->execute() == true) {
        for (i = 0; i < statements->length(); i++) {
            result = statements[i]->execute();
            if (result.type == BREAK)
                break;
            if (result.type == CONTINUE)
                i = 0;
        }
    }
    

    As you add more forms of flow control this signalling becomes more and more expensive. Once you add exceptions (eg. flow control that can happen everywhere) you start needing to check for these things in the middle of even basic arithmetic, leading to ever increasing overhead. If you want to see this in the real world I encourage you to look at the ECMAScript spec, where they describe the execution model in terms of an AST interpreter.

    In a bytecode interpreter these problems basically go away, as the bytecode is able to directly express control flow rather than indirectly through signalling, eg. continue is simply converted into a jump instruction, and you only get that cost if it’s actually hit.

    Finally an AST interpreter by definition is recursive, and so has to be prevented from overflowing the system stack, which puts very heavy restrictions on how much you can recurse in your code, something like:

    1+(1+(1+(1+(1+(1+(1+(1+1)))))))
    

    Has 8 levels of recursion (at least) in the interpreter — this can be a very significant cost; older versions of Safari (pre-SquirrelFish) used an AST interpreter, and for this reason JS was allowed only a couple of hundred levels of recursion vs 1000’s allowed in modern browsers.

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

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, your concerns are legitimate. You need to use specifically… May 16, 2026 at 11:15 pm
  • Editorial Team
    Editorial Team added an answer As you said you can write a JavaScript code to… May 16, 2026 at 11:15 pm
  • Editorial Team
    Editorial Team added an answer You should look up the ICommand interface and implement it… May 16, 2026 at 11:15 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Hy, I'm interested in some general optimisation methods in an asp.net ajax project for
Speed, optimization, and scalability are the typical comparisons between the Udp and Tcp protocols.
I'm interested in implementing a Forth system, just so I can get some experience
I have a piece of code for some validation logic, which in generalized for
Thanks to some very helpful stackOverflow users at Bit twiddling: which bit is set?
I was interested in writing some home-brew analytic solutions and all the click tracking
Just to get it out of the way... Premature optimization is the root of
As a way to get used to python, I am trying to translate some
FOR SEARCH ENGINE OPTIMIZATION PURPOSES , does the location of the slug within a
I'm a little confused about the granularity offered by the HttpResponse.RemoveOutputCacheItem() call. I'm interested

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.