Why OOP is not Performance Efficient
Discussion center for current topic is why we basically require to move away from object oriented programming. As we all know Object Oriented pattern is something we have been using to solve almost all our technical problems contrary of the complexity. Because of simple and scalability of object oriented programming.
But Object Oriented has a limit of performance due to the fact that we ignore cache lines and modern CPU architectures and internal layouts working under this paradigm.
Being a game developer and working closely on optimization process of Entertainment Products, my experience depicts that performance plays a very crucial role in project development as well as user experience you can add great amount of features if you are not being halted by performance issues while for user perspective performance optimization can sooth the user experience.
For better understanding lets brush off our basic concepts of modern processors.
We know that modern processors contain Cache Lines or cache in them as a fast memory access pipeline, because modern processors as really fast and memory architecture is still not fast enough to provide data to processors at their required rate hence whatever maybe the speed of the processor if it has to get data from the memory it will bottleneck and face data latency. To remove this processors are assigned cache memories which use hardware prefetching and highest speed Cache (L1) is considered to provide 27% faster data rate as compared to direct memory access.
Mostly cache lines are 64 byte or 32 byte depending upon the architecture. Cache cannot read less or more than its bandwidth, if the resources to load are less than 64 bytes than to fullfil the cache we would have loaded additional data resources and process called hardware prefetching.
Introduction of multiple cores processors have also increased the performance capabilities as each processor core has its own cache line so we can have greater speeds and performance.
Cache also use a concept of locality which are temporal locality and spatial locality. When the required resource is close to the cache in the memory and the cache latency is pretty low or least it is called spatial locality.
While if the required resource is the value which was already being cached previously it is called temporal locality.
When an instruction is run the data required by it is first checked in the processor's registers which are closest to the processor but as they are very low in size so they are almost negligible when discussion the Cache Lines and the request is than forwarded to Cache lines for the resources. If the data is present in the cache line and provided to CPU it is called a Cache hit but if the data is not provided it is called Cache Miss and then request is forwarded to Paging(memory) which is slower and process is called Cache latency as cache is facing a latency providing data resources to processor.
A cache latency can be 100~300 processor cycles means it will wait for the memory to provide the data causing performance halting.
Point to ponder Why do we care for such processes, programming in oop is any way connected to the above discussion.
When working with object oriented programming, we know that everything is basically objects. Objects are the basic component of object oriented. We have the information and methods encapsulated in an object with limited access. An object can contain any piece of information and an instance of it can contain good amount of memory.
We can observe that the student object has 168 bytes which currently exceeds our cache line limit so iterating over a collection of student like a method
We have a method to calculate the student with certain percentage we write a simple
In the above we can see that we are loading 168 byte of object from a random memory location at every iteration which causes cache overflowing and most probably triggering a cache miss because there is a certainty that the desired resource is not loaded hence triggering a cache latency and since working with object oriented data in memory is layout randomly so there is chance we get highest cache latency will lead us to performance issues because we are having latency.
While the amount of resource we desire is only 4 byte and loading additional 164 byte is causing us cache overflow.
This point is important when the applications require performance.
Every iteration we get a cache miss triggering a cache latency and waiting time is variable depending upon the position because we cant predict where is the object situated.
If we would be using structs instead of objects here we would have got a predictable linear memory layout hence improving a bit of cache latency by usage of spatial locality, but still would facing cache latency.
The solution to such problems when start occurring are changing programming procedures for performance using cache lines in effective process.
Data Oriented patterns are relatively being brought programming practices at industrial level specifically game development industry is adapting to this pattern for performance hungry products.
Working in oop if we observe a class named 'Percentile' we might be pretty annoyed, but working with data oriented we might possibly have to adapt because the project is being layout for better performance.
Another point to ponder is when working we normally don't consider using multiple cores of the modern processors. What should we do in the case to use the full capabilities and juice out the performance from the target.
We should be looking towards using an OS-model process called 'Jobs System' for our process to use each processor core and caches to maximize the performance so in this case we might get performance.
Take your decide from 300+ actual slots on-line, which include an unimaginable choice of award-winning Microgaming titles expertly designed to both enthrall and entertain. If a site makes its means onto our record internet sites|of websites} to keep away from, it means it has failed some or all of our 25-step casinoreview course of. We take a look at|have a look at} issues like the variety and equity of the video games, the conditions around bonuses and promos, the banking options, licences and site safety. Pragmatic Play works intently with its regulatory our bodies and licensees to ship a world-class stay casino expertise at all times. The newest product in our portfolio is the perfect choice for those who|for many who|for people who} search a easy, low-limit Roulette table. The mechanism behind Auto-Roulette releases a ball into the spinning wheel in the course of the betting time, powering 먹튀사이트 먹튀프렌즈 a fast gameplay in an intimate environment, with zero human interaction.
ReplyDeleteAppreciate you blogging thhis
ReplyDelete