Noob questions about performance

Recommended Posts

Posted (edited)

This question are so basic that I feel bad opening a topic for it, whish there was a chat instead, maybe I should propose that later :D

 

Anyway, here's my code:

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	OpenDoor(DeltaTime);
}

void UOpenDoor::OpenDoor(float DeltaTime) {

	float RotationAmmount = RotationSpeed * DeltaTime;
	if (!FMath::IsNearlyEqual(CurrentYaw, OpenYaw, RotationAmmount))
	{
		float NewYaw = CurrentYaw - RotationAmmount;
		CurrentYaw += NewYaw < -180 ? NewYaw + 360 : -RotationAmmount;
		GetOwner()->SetActorRotation(FRotator(0.f, CurrentYaw, 0.f));
	}
}

My question pertains the OpenDoor() function called every frame.

As you see I'm creating 2 floats inside of it every frame(let's assume this door keep opening forever), is this a good practice or since it happens every frame I should rather have those 2 floats as persistent private variable of my class? Between the two methods, there can be any noticeable performance difference with many assets that create 2 floats at every frame?

My second question is similar to the first, but is about the GetOwner() function called every frame. Should I rather store a Owner pointer in my class? Can this become noticeably expensive if I have many objects calling GetOwner function at every frame?

Edited by MarcusAseth

Share this post


Link to post
Share on other sites
Just now, MarcusAseth said:

This question are so basic that I feel bad opening a topic for it, whish there was a chat instead, maybe I should propose that later

https://www.gamedev.net/community/chat/

 

Regarding the variables:

floats (and other built-in values) are trivial. Don't worry about them, unless you're creating an absolutely insane amount of stuff every frame. If you are, you're likely doing other stuff completely wrong in the first place.

 

Regarding GetOwner:

This could probably do with being cached. Look it up once at the start and store it.

 

Apart from that:

When dealing with performance, you should always be armed with a profiler. Measure, change, measure again. Additionally, worrying too much about performance when performance isn't an issue is very likely to be a waste of time. Focus on getting stuff working.

Share this post


Link to post
Share on other sites

Thanks Lactose, I'll store Owner pointer then :P 

I'm not ready yet to measure stuff I think, no idea of what I am doing, and I would probably end up measuring the wrong things and jumping to wrong conclusions based on that. Unfortunately from time to time the "fear of bad performance ghost" (which I never met) comes back up and distract me from the currently relevant stuff :S

Glad there is a chat, is it a voice chat only though? I can only type :/

 

Share this post


Link to post
Share on other sites
Just now, MarcusAseth said:

Thanks Lactose, I'll store Owner pointer then  

I'm not ready yet to measure stuff I think, no idea of what I am doing, and I would probably end up measuring the wrong things and jumping to wrong conclusions based on that. Unfortunately from time to time the "fear of bad performance ghost" (which I never met) comes back up and distract me from the currently relevant stuff

Glad there is a chat, is it a voice chat only though? I can only type

 

Learning to use a profile is, like learning to use a debugger, a very valuable skill. It might not be critical right now, but if you run into actual performance issues later on, I would highly recommend investing the time then.

 

The chat is text, using Discord.

Share this post


Link to post
Share on other sites

What is the chance that the compiler makes your float global for you ?, it could be possible you dont know how its being optimized.

 

About the GetOwner() , indeed is better to have a pointer at initialize.

 

The best optimization is to perform 1 door every frame, not all doors,

you have a list, call list->opendoor()

then set the pointer in the list to the next door, ready to check in the next frame.

You should do this for everything where possible btw, spread it out over more frames if timing is not crucial.

Share this post


Link to post
Share on other sites
Posted (edited)

That's interesting, though I have some doubts:

let's say someone PC is running the game at 30 fps and I have 100 doors in my list, let's say the pointer is at the first door of the list and the player is in front of the last door on the list, now they have to stand in front of this door little more than 3 seconds before something happens, right? And that would be considered a bug by the player

Oh well, I bet is the reason you said " if timing is not crucial" :P

Edited by MarcusAseth

Share this post


Link to post
Share on other sites

Keep in mind this sort of logic is often trickier to write than the straight-forward alternative. And even correctly implemented, it might not have any noticable effect on your game's performance -- there might be other problems dwarfing whatever gain you can get from this setup.

It might very well be a good option in a lot cases (it's a fairly common technique) where it's applicable, but when it comes to anything relating to performance, the best option is always to profile and go from there. Measure, change, measure & compare. Repeat until good enough.

 

1 minute ago, the incredible smoker said:

No, you have only the doors of the current zone in the list.

It's easy to imagine a scenario where the design calls for 100 doors on-screen and wanting to open them all at once, in perfect sync. Or a scenario where timing of two different doors must be the same.

Your suggestion isn't a solution for every single case -- like you said, only if timing is not crucial. Sometimes, timing is crucial.

Share this post


Link to post
Share on other sites

Going on a bit, since this is For Beginners and you write that you aren't really sure what to do, the answer is that you shouldn't be worried about performance yet.

Anything you write as an individual is unlikely to tax your computer.  The only real exception to that is things that are breathtakingly wrong from a programming perspective. In that case the problem creates a learning exercise for you.  If you encounter those, people on the forum can usually help you spot them easily. Also, they'll usually be the things you've changed most recently.

Your computer is able to perform many hundred million operations every frame.  Consider the biggest video games your computer can handle, then realize that it can handle all of that work.  Creating a variable is approximately nothing.  Sorting hundreds of game objects in the world based on distance is approximately nothing. 

 

After you gain experience, when you understand more about programming and know several variations and assorted algorithms to accomplish a task, and when you're in a position to understand the tradeoffs between those algorithms, that's when you'll be ready to start having good conversations about performance.

Share this post


Link to post
Share on other sites
On 27/08/2017 at 0:09 AM, MarcusAseth said:

My second question is similar to the first, but is about the GetOwner() function called every frame. Should I rather store a Owner pointer in my class?

Do you have the source code there?

If you do, you can see that GetOwner() is a FORCEINLINE function which returns a copy of a cached 'OwnerPrivate' pointer. It's already pretty much as fast as it can be, so there's no need to cache it yourself.

Share this post


Link to post
Share on other sites
7 minutes ago, Kylotan said:

Do you have the source code there?

If you do, you can see that GetOwner() is a FORCEINLINE function which returns a copy of a cached 'OwnerPrivate' pointer. It's already pretty much as fast as it can be, so there's no need to cache it yourself.

That's really interesting and good to know :o

 Thanks! :)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Forum Statistics

    • Total Topics
      628662
    • Total Posts
      2984095
  • Similar Content

    • By lawnjelly
      It comes that time again when I try and get my PC build working on Android via Android Studio. All was going swimmingly, it ran in the emulator fine, but on my first actual test device (Google Nexus 7 2012 tablet (32 bit ARM Cortex-A9, ARM v7A architecture)) I was getting a 'SIGBUS illegal alignment' crash.
      My little research has indicated that while x86 is fine with loading 16 / 32 / 64 bit values from any byte address in memory, the earlier ARM chips may need data to be aligned to the data size. This isn't a massive problem, and I see the reason for it (probably faster, like SIMD aligned loads, and simpler for the CPU). I probably have quite a few of these, particular in my own byte packed file formats. I can adjust the exporter / formats so that they are using the required alignment.
      Just to confirm, if anyone knows this, is it all 16 / 32 / 64 bit accesses that need to be data size aligned on early android devices? Or e.g. just 64 bit size access? 
      And is there any easy way to get the compiler to spit out some kind of useful information as to the alignment of each member of a struct / class, so I can quickly pin down the culprits?
      The ARM docs (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html) suggest another alternative is using a __packed qualifier. Anyone used this, is this practical?
    • By Josheir
      In the following code:

       
      Point p = a[1]; center of rotation for (int i = 0; I<4; i++) { int x = a[i].x - p.x; int y = a[i].y - p.y; a[i].x = y + p.x; a[i].y = - x + p.y; }  
      I am understanding that a 90 degree shift results in a change like:   
      xNew = -y
      yNew = x
       
      Could someone please explain how the two additions and subtractions of the p.x and p.y works?
       
      Thank you,
      Josheir
    • By Anderfell
      **[ROYALTY]**
       
      Hello my name is Brandon and I am currently one of the co owners of the team Digital Forged Studios.
       
      We are currently seeking two new members for our team, before applying you must be aware that we are seeking people that are 100% committed to this project, you must be reachable within the day, replying to questions or responding to our messages and in general be actively online, otherwise I ask nicely that you do not apply.
       
      The persons we are seeking are an experienced Programmer with knowledge  in c++, c#, and or unreal script, the c++ and familiarity with unreal is the main thing were seeking, other teams we are currently looking for are 3D artists to work on Humanoid models Props and more, were are also seeking other team members such as Generalists that understands the Unreal Engine, Animators for Human, Non Human and Objects were keeping the team small and having whats needed so feel free to apply.
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      [SEEKING CURRENT POSITIONS]
       
      [Animators] x 2 [ You will be doing Human, Non Human, and Objects like Machines and Doors, Environment assets. ]
      [3D Artist] x 2 [ You will be focusing on Humans, Objects, and Environment modeling would also like skills in texturing. ]
      [Generalist] x 1 [ We would like someone that has good knowledge of Unreal Engine that can set up anything we need in Engine. ]
      [Writer] x 1 [ We would need someone that can work with me on game documents, organisation of documents story arcs, character development, dialogue creation, text editing and other text related jobs. ]
      [PROGRAMMER] "As above"
       
      The project is Royalties and when any fund raising is made you will also receive some funding based off that, this is divided depending on amount of work done as an example per asset made toward the game, there are no contracts at this stage and everything known is in documents at the moment.
       
      The game is a Action RPG with online elements this will be an ongoing project, we are running ssh servers, and Prefroce. We have a small staff of experienced people.
       
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      We do have some artwork to show of the world a little and what it's about, If you are interested in joining the project please contact us at:
       
      Anderfell info:
      Anderfell#5123 on Discord
      nevarra@hotmail.com email
       
      Shadefix info:
      Shadefix#0570 on Discord
      androes.matthijssens@gmail.com email
      We are active on Discord and maybe take a day or two to reply to emails on our website as we receive a few a daily we need to sort through thanks. 
      https://digitalforgedstudios.com/
      ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      Comic Panel
      http://imgur.com/a/905pd
       
      Artwork
      http://imgur.com/a/0JchV
      Models
      http://imgur.com/a/jdhWu
       
      Game Document
      https://docs.google.com/document/d/1bNlP-qwR15BLGG66hDUcewqlWIPP4flnHxRwxfhNmTE/edit?usp=sharing
       
      Regards Brandon
      Digital Forged Game Development Team.
       
      Some Progress
       





       
       





    • By i3DTutorials
       

       
      Game School Online™ Announces Winter Enrollment Open Through December
      Los Angeles, CA - December 2017
       
      Free Winter Term Enrollment!
      Free Winter Enrollment:
      Game School Online™, the first and only free online game development school of its kind, has opened enrollment for the winter term, which begins in January of 2018. GSO™ currently offers curricula in environment art and lighting for games, focusing specifically on Unreal Engine 4. GSO™ will be adding two new courses for the winter term, “Advanced Lighting Concepts with Unreal Engine 4” and “Advanced Hard Surface Modeling.”

       
      Free Workshop!

       
      December Free Workshop:
      In addition to winter enrollment, GSO™ will have a free online workshop, “Animating For Games and Movies”, with Veara Suon, Senior Animator at Double Negative. Veara has worked in the AAA games industry, working on franchises like Destiny and Bioshock. Veara also works in the film industry, having worked for famed studios like Weta, ILM, and Sony, contributing to films like Pacific Rim 2, Spiderman, and Avengers. In this month’s free GSO™ workshop, Veara will be discussing topics such as:
      Sharing techniques on how he animates for games and film
      Advice on how students can get a job in games or film
      Advice on how working professionals can switch from games to film, and vice versa
      Job relocation
      The workshop will last for an hour, with allocated time for Q & A from the audience. The workshop will take place on December 14 at 8pm PST. As usual, our monthly workshops are absolutely free and anyone is welcomed to join us. To RSVP, please visit our Facebook page here: https://www.facebook.com/events/139461393377301/?active_tab=about

       
      Scholars Available For Mentoring!
      Scholar Lineup:
      Scholars are our mentors, working industry professionals currently working on your favorite games and franchises- here to help you learn to be a professional game dev, with one on one live private sessions. Our current lineup of scholars includes:
       
      Brian Yam - Director of Visual Development @ Section Studios
      https://bdyammer.artstation.com/
      https://www.linkedin.com/in/yambrian/
       
      Olaf Piesche - Senior Engineer @ Epic Games
      https://www.linkedin.com/in/olaf-piesche-0938292/
       
      Kevin DeBolt - World Artist @ 343 Industries
      http://kevindebolt.com/index.html
      https://www.linkedin.com/in/kevin-debolt-52058844/
       
      Rosie Katz - Senior Game Designer @ EA, Visceral, Sledgehammer Games
      http://www.rosiewrede.com/index.php?nav_bar=level_design
      https://www.linkedin.com/in/rosiewrede/
       
      Leo Gonzalez - Senior Artist @ Certain Affinity
      https://leog.artstation.com/
      https://www.linkedin.com/in/leo-g/
       
      Brandon Pham - Lead Environment Artist
      https://brandonpham.artstation.com/
      https://www.linkedin.com/in/brandon-pham-a490497/

       
      We believe that education should be free for everyone! Come join us at Game School Online™ and see what the future of game development education looks like today! For more information about Game School Online™, available courses, scholars, and events, please visit http://gameschoolonline.com/


       
      Facebook: https://www.facebook.com/gameschoolonline/
      Twitter: @GSOscholar
      Discord: https://discordapp.com/invite/BzU5Fq2
      Patreon: https://www.patreon.com/gameschoolonline


       
      About Game School Online™ (GSO™)
      Game School Online™ is the first ever, completely free game development training program. GSO™ was founded by veteran developers working in the AAA games and entertainment industries. Featuring courses authored by working industry professionals, students are able to learn production techniques and workflows used to ship some of the biggest IPs and AAA franchises. Industry pros known as “scholars”, work with students providing private live sessions to help you become “industry” ready. All courses are available for free, no trials or demos- it’s completely free for anyone that wants to learn how to become a skilled game developer. For more information, please visit our website: http://gameschoolonline.com/
      Game School Online™ and GSO™ are registered trademarks Game School Online, LLC. All other brand names, product names or trademarks belong to their respective holders.
       
      Contact
      Game School Online, LLC.
      info@gameschoolonline.com

      View full story
    • By i3DTutorials
       

       
      Game School Online™ Announces Winter Enrollment Open Through December
      Los Angeles, CA - December 2017
       
      Free Winter Term Enrollment!
      Free Winter Enrollment:
      Game School Online™, the first and only free online game development school of its kind, has opened enrollment for the winter term, which begins in January of 2018. GSO™ currently offers curricula in environment art and lighting for games, focusing specifically on Unreal Engine 4. GSO™ will be adding two new courses for the winter term, “Advanced Lighting Concepts with Unreal Engine 4” and “Advanced Hard Surface Modeling.”

       
      Free Workshop!

       
      December Free Workshop:
      In addition to winter enrollment, GSO™ will have a free online workshop, “Animating For Games and Movies”, with Veara Suon, Senior Animator at Double Negative. Veara has worked in the AAA games industry, working on franchises like Destiny and Bioshock. Veara also works in the film industry, having worked for famed studios like Weta, ILM, and Sony, contributing to films like Pacific Rim 2, Spiderman, and Avengers. In this month’s free GSO™ workshop, Veara will be discussing topics such as:
      Sharing techniques on how he animates for games and film
      Advice on how students can get a job in games or film
      Advice on how working professionals can switch from games to film, and vice versa
      Job relocation
      The workshop will last for an hour, with allocated time for Q & A from the audience. The workshop will take place on December 14 at 8pm PST. As usual, our monthly workshops are absolutely free and anyone is welcomed to join us. To RSVP, please visit our Facebook page here: https://www.facebook.com/events/139461393377301/?active_tab=about

       
      Scholars Available For Mentoring!
      Scholar Lineup:
      Scholars are our mentors, working industry professionals currently working on your favorite games and franchises- here to help you learn to be a professional game dev, with one on one live private sessions. Our current lineup of scholars includes:
       
      Brian Yam - Director of Visual Development @ Section Studios
      https://bdyammer.artstation.com/
      https://www.linkedin.com/in/yambrian/
       
      Olaf Piesche - Senior Engineer @ Epic Games
      https://www.linkedin.com/in/olaf-piesche-0938292/
       
      Kevin DeBolt - World Artist @ 343 Industries
      http://kevindebolt.com/index.html
      https://www.linkedin.com/in/kevin-debolt-52058844/
       
      Rosie Katz - Senior Game Designer @ EA, Visceral, Sledgehammer Games
      http://www.rosiewrede.com/index.php?nav_bar=level_design
      https://www.linkedin.com/in/rosiewrede/
       
      Leo Gonzalez - Senior Artist @ Certain Affinity
      https://leog.artstation.com/
      https://www.linkedin.com/in/leo-g/
       
      Brandon Pham - Lead Environment Artist
      https://brandonpham.artstation.com/
      https://www.linkedin.com/in/brandon-pham-a490497/

       
      We believe that education should be free for everyone! Come join us at Game School Online™ and see what the future of game development education looks like today! For more information about Game School Online™, available courses, scholars, and events, please visit http://gameschoolonline.com/


       
      Facebook: https://www.facebook.com/gameschoolonline/
      Twitter: @GSOscholar
      Discord: https://discordapp.com/invite/BzU5Fq2
      Patreon: https://www.patreon.com/gameschoolonline


       
      About Game School Online™ (GSO™)
      Game School Online™ is the first ever, completely free game development training program. GSO™ was founded by veteran developers working in the AAA games and entertainment industries. Featuring courses authored by working industry professionals, students are able to learn production techniques and workflows used to ship some of the biggest IPs and AAA franchises. Industry pros known as “scholars”, work with students providing private live sessions to help you become “industry” ready. All courses are available for free, no trials or demos- it’s completely free for anyone that wants to learn how to become a skilled game developer. For more information, please visit our website: http://gameschoolonline.com/
      Game School Online™ and GSO™ are registered trademarks Game School Online, LLC. All other brand names, product names or trademarks belong to their respective holders.
       
      Contact
      Game School Online, LLC.
      info@gameschoolonline.com
  • Popular Now