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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:32:55+00:00 2026-06-09T11:32:55+00:00

I have an object that is nested several levels deep which I’m referencing multiple

  • 0

I have an object that is nested several levels deep which I’m referencing multiple times. Is it faster to create and set a reference to that object or does it matter?

Context
I heard that it is faster to create a local reference. This is years ago and for a Visual Basic project. But this is Flash. And the output is a SWF / bytecode. And the compiler could look at that reference and do what I’m doing so that the object does not have to be looked up each time.

For example:

public function doStuff():void {

    Model.instance.view1.button1 = button1;
    Model.instance.view1.button2 = button2;
    Model.instance.view1.button3 = button3;
    Model.instance.view1.button4 = button4;
    Model.instance.view1.button5 = button5;
    Model.instance.view1.button6 = button6;

    // more fake code referencing more something.something.something like things 

    for (var i:int;i<something.something.something.length;i++) {
        var result:Object = Controller.staticMethod(button1);
        var result2:Object = Controller.staticMethod(button1);
    }
}

Vs:

public function doStuff():void {
    var view1:View = Model.instance.view1;

    view1.button1 = button1;
    view1.button2 = button2;
    view1.button3 = button3;
    view1.button4 = button4;
    view1.button5 = button5;
    view1.button6 = button6;
}

.
Taking Baris suggestion I tested it for myself. Below are the results (though I don’t know how to interpret them into the actual difference ie ‘method 1 is .000001 faster than method 2’).

Results

Test 1

            var instance:Model = Model.instance;

            var startTime:int = getTimer();
            for(var i:int = 0; i<10000000; i++){
                instance.url = "";
            }
            trace(getTimer()-startTime); // 826, 929, 823

            var startTime:int = getTimer();
            for(var i:int = 0; i<10000000; i++){
                Model.instance.url = "";
            }
            trace(getTimer()-startTime); // 3483, 3976, 3539

Test 2

            var instance:Model = Model.instance;

            var localLogo:BitmapImage = Model.instance.logo;

            var startTime:int = getTimer();
            for(var i:int = 0; i<10000000; i++){
                localLogo = logo;
            }
            trace(getTimer()-startTime); // 2070, 2083, 2110

            var startTime:int = getTimer();
            for(var i:int = 0; i<10000000; i++){
                instance.logo = logo;
            }
            trace(getTimer()-startTime); // 2028, 2509, 2154
  • 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-06-09T11:32:56+00:00Added an answer on June 9, 2026 at 11:32 am

    Generally, the as3 compiler is not that smart as we think. I think it does that to reduce compilation times.

    This page http://upshots.org/actionscript/20-tips-to-optimize-your-actionscript gives us a rule:

    5: The one-dot rule When accessing nested variables, anytime a
    variable requires even one level of scope shift to discover, and is
    referenced more than once, save it to local variable. In drawing
    classes, you’ll often see Math.PI / 2 referenced within loops that
    might iterated hundreds of times each frame – that value should be
    stored in a local variable. Note that this is not true when
    referencing member methods. Saving Math.PI to a variable is
    appropriate; saving Math.round to a variable is not.

    It does make difference, but to a software building perspective, the more readable code would be the propper way to do it, unless it’s critical code, like a physics section of your app.

    Other than making time benchmarks, you can inspect the bytecode too, using this tool http://www.swfwire.com/

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

Sidebar

Related Questions

Explanation: Let's say I have an object graph that's nested several levels deep and
I have been writing several class templates that contain nested iterator classes, for which
I have a Bank Object that has several nested objects/properties/methods as well as wrapping
I have an Array nested withing an Object that's inside an Object which is
I have a nested JSON object that I need to loop through, and the
I have an entity that needs to be grouped several times by three of
I have javascript object which consists of complex array of structures with nested structures
I have several models that includes nested classes and lists. Many of the class
I have an object that consists primarily of a very large nested dictionary: class
I have an object model that contains several lists of other objects. I want

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.