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

  • Home
  • SEARCH
  • 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 7789643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:21:32+00:00 2026-06-01T21:21:32+00:00

I have a Matrix which I recycle and use for drawing DisplayObject instances onto

  • 0

I have a Matrix which I recycle and use for drawing DisplayObject instances onto a Bitmap.

At the moment, I reset the Matrix before I render each item, like this:

_matrix.a = 1;
_matrix.b = 0;
_matrix.c = 0;
_matrix.d = 1;
_matrix.tx = 0;
_matrix.ty = 0;

Would it be better to do the above, or to simply do this?:

_matrix = new Matrix();

Generally I would say the former, however I’m unsure if in the case of Matrix there is some heavy stuff going on for each of those properties that I reset (mathematically).

  • 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-01T21:21:34+00:00Added an answer on June 1, 2026 at 9:21 pm

    I think reusing the same instance of Matrix is more efficient than creating a new one every time.

    In fact, creating a new instance is a relatively heavy operation and that’s why caches are used: to create a few instances and reuse them instead of creating a high number of instances.

    I run a little benchmark and it confirms my answer:

    var t:Number;
    var i:int;
    var N:int = 10000000;
    
    t = getTimer();
    for (i = 0; i < N; i++) {
        _matrix = new Matrix();
    }
    trace(getTimer()-t); // 7600
    
    
    t = getTimer();
    for (i = 0; i < N; i++) {
        _matrix.a = 1;
        _matrix.b = 0;
        _matrix.c = 0;
        _matrix.d = 1;
        _matrix.tx = 0;
        _matrix.ty = 0;
    }
    trace(getTimer()-t); // 4162
    

    Finally, note that the difference is not that much great and that creating 10000000 new instances takes only 7600 ms, so unless you are creating thousands of matrices per frame, either approach wouldn’t have a noticeable impact on performance.


    EDIT:

    Using the method identity will have the advantages of both approaches (simplicity and performance):

    t = getTimer();
    for (i = 0; i < N; i++) {
        _matrix.identity();
    }
    trace(getTimer()-t); // 4140
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the first matrix which should account for each users (in lines) which
I have a 4x4 matrix which I wish to decompose into 4 frequency bands
I have a code base, in which for Matrix class, these two definitions are
I have a data set which consists of an ID and a matrix (n
I have a 30000x14000 sparse matrix in MATLAB (version 7), which I need to
I have a datset, which is dat<-matrix(seq(1:5290),c(115,46)) How can I convert dat to a
I am creating a traceability matrix for PRD. I have test case _id which
I have a large matrix from which I would like to gather a collection
I have a set of data in a matrix which I would like to
I have a matrix X(1e4,20) which takes on values 0:4 . I'm interested in

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.