sntx

Performance Optimisation - Setting identical properties

Recommended Posts

Dear community,

Does Pixi ignore calls to set properties if the values are not changed?

 

For example, let's say I have the following animation step function:

step() {
  mySprite.x = someXVal
  mySprite.y = someYVal
  mySprite.angle = someAngleVal
  // etc...
}

 

Should I check if values have changed before setting them again? 

step() {
  if (mySprite.x !== someXVal) mySprite.x = someXVal
  if (mySprite.y !== someYVal) mySprite.y = someYVal
  if (mySprite.angle !== someAngleVal) mySprite.angle = someAngleVal
  // etc...
}

 

Obviously this example is simplified, it's purpose is just to illustrate my question. I'm thinking of the architecture of my application here and deciding what patterns to use. Another approach would be a dirty flag:

step() {
  if (isDirty) {
    mySprite.x = someXVal
    mySprite.y = someYVal
    mySprite.angle = someAngleVal
    // etc...
  }
  isDirty = false
}

 

Re-stating my question: Do I need to implement a system for checking and setting only updated properties for PIXI objects or does PIXI already do this internally?

As my application grows bigger, this would be an important decision, specially in terms of architecture and performance.

 

Thanks!

Santiago

 

Share this post


Link to post
Share on other sites

No, you dont have to do it. Some fields are done internally, some dont matter because they're processed every frame anyway, but of course there are big operations that shouldn't be called each frame.

Avoid clearing&filling graphics every frame if you dont need it, for example.

Edited by ivan.popelyshev

Share this post


Link to post
Share on other sites

Hi Ivan,

Thanks for your quick response! I knew about clearing and filling graphics, have been reading about that already. Can I read more about this subject somewhere? I know that some properties are fast (like setting tint, for example) and others aren't. Is there some sort of reference on this? Which properties are fast to set and modify and which ones are slow?

Thanks again!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.