[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]

/agdg/ - Amateur Game Development General

AGDG - The Board
Name
Email
Subject
REC
STOP
Comment *
File
Password (Randomized for file and post deletion; you may also set your own.)
Archive
* = required field[▶Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Oekaki
Show oekaki applet
(replaces files and can be used instead)
Options
dicesidesmodifier

Allowed file types:jpg, jpeg, gif, png, webp,webm, mp4, mov, swf, pdf
Max filesize is16 MB.
Max image dimensions are15000 x15000.
You may upload5 per post.


Welcome to AGDG, keep working on your game anon!
See also: /ideaguy/ | /vm/

File: 1470236811160.png (153.56 KB,814x525,814:525,CPUMemoryGap.png)

4a79bc No.27468

Object-Oriented Design kills performance in some places. This is something I've been banging my head over for the last few days and decided to create a thread to share what I've found/Maybe others can help.

The basic idea is: Remember what you're programming on. Your CPU is 10-20x faster than your memory. Your CPU also has a little chip of memory called cache. The idea behind DOD is you try to use this memory as much as possible to avoid as many lookups as possible. The most common way to do this you make very very small data objects (important because theres not much cache memory) and put each object in its own giant array of its relevant objects. Then your cache can load this array in and you can just run through it once, instead of jumping all over the place around an array of objects constantly dereferencing shit and making the CPU do all sorts of lookups.

A basic example of this being implemented:


''OOP''
Class dog {
sound bark;
attack bite;

''DOD''
std::vector<sound>
std::vector<bite>

This way it's all organized in a way so when you play your sounds, you just send the sound vector to the sound processor class and it just runs through the vector (preferably &(vector[0]) so it's the raw array) and does what it needs. There is no unnecessary data being passed over.

____________________________
Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27469

File: 1470237289763-0.png (38.38 KB,1002x389,1002:389,id_lookup_3.png)

File: 1470237289763-1.png (25.94 KB,1011x324,337:108,id_lookup_2.png)

This creates an interesting idea though. If your entity is just a bunch of vectors do you need the entity in the first place? It will just be the sum of its components. Then how do you keep track of what is where? Well a lot of programmers seem to imply that you make all the vectors the size of entities you have, keep them all parallel, and if the entity doesn't have a specific thing then just leave it empty. Your entity will be nothing more than the integer identifying where it is in the vectors.

Then you do either 2 things. You make your array remember where the start-end of empty spaces are, or you can make a second array of indexes and just iterate through that.

2 articles that talk about this: http://bitsquid.blogspot.co.at/2011/09/managing-decoupling-part-4-id-lookup.html https://blog.molecular-matters.com/2013/07/24/adventures-in-data-oriented-design-part-3c-external-references/

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27470

File: 1470238338604.png (183.85 KB,3566x1262,1783:631,cachemisses.png)

This is getting to the point where I don't understand DOD anymore. It's probably because I don't understand cache, and I have a lot of questions I still need to find the answers of. Pic related raise a LOT of questions for me.

>What causes cache to throw data out?

>Will iterating backwards cause a cache miss?

>Does iterating through the array of indexes keep the array of indexes in cache or does it get thrown out when you move to the array it's going through

>If you put your easy to cache data through a complex procedure (say collision detection) wont the cache throw it out, store something else, and then have to re-cache is just to use it once then throw it out again?

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27473

>>27468

The classic design discussion on this topic OP:

http://gameprogrammingpatterns.com/data-locality.html

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27477

>>27470

I actually discovered why this pic is the case.

Each cache line is 64 bytes, which means it can hold 16 32 bit integers. So when you skip every 16 lines you literally expend the entire cache line. This picture wasn't very clear on that.

>>27473

I remember reading this article. The hot/cold splitting was a very good thing to remember from it.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27478

YouTube embed. Click thumbnail to play.

This is the goto-video for data oriented design. Basically what really put it out there from what I've seen.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27479

YouTube embed. Click thumbnail to play.

This video has a ton of really good information on how caches work in general.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27574

>>27478

>>27479

Good videos, thanks.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27882

Ubisoft uses global lists. Not singletons, just straight up global lists. They have a singleton to initialize and destroy it, but that's it. OOP is a meme that will fuck up your engine hard if you believe in it too much.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27886

>>27882

It's not that OOP is inherently bad, it's just that everything has a time and place. OOP emphasizes encapsulation, which means that it cuts down on race-conditions (used correctly) and makes code easier to understand what each objects does. It also helps with code-reuse, which cuts down on development time. The converse to this is that OOP has more overhead, so when you need to do something quickly or many, many times, it's more effective to make use of more DOP style of programming. The best programs will have a combination of both where it makes sense.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.

4a79bc No.27892

>>27886

I didn't mean it was bad, it's just been catapulted into meme status and it's out of hand. It's fucked me over so many times because I buy into this "never use globals", "encapsulate everything" shit. The OOP meme makes you think you should use objects at absolutely every chance you get,but real world devs basically break code down into "Code that runs 90% of the time" and "Code that runs 10% of the time". You use OOP in one DOP in the other.

Disclaimer: this post and the subject matter and contents thereof - text, media, or otherwise - do not necessarily reflect the views of the 8kun administration.



[Return][Go to top][Catalog][Nerve Center][Random][Post a Reply]
Delete Post [ ]
[]
[ / / / / / / / / / / / / / ] [ dir / random / 93 / biohzrd / hkacade / hkpnd / tct / utd / uy / yebalnia ]