Full Text 01
Full Text 01
Full Text 01
performance between
Object-oriented Design and
Data-oriented Design in Mobile
games.
Scope: 15 credits
Date: 2021-02-13
Abstract
Acknowledgments
We want to thank our Examiner Johannes Schmidt for guiding us with interesting
and helpful feedbacks.
We want to thank our supervisor Domina Robert Kiunsi for always being there
when we needed help throughout the writing process.
We want to thank our teachers for helping us develop our knowledge and
competence during these three years at the university.
Finally, we want to thank our families for their support and encouragement.
1
Abstract
Abstract
The popularity that mobile games gained recently gives the opportunity to develop more mobile
games. Limited by the scarce resources on mobile phones, developing good games becomes
critical and requires special optimization while choosing the design approach.
Object-oriented Design (OOD) and Data-oriented Design (DOD) are two programming
paradigms that have different ways of defining and structuring data. The purpose of this student
thesis is to investigate the CPU and Memory performance differences between the two
approaches.
To answer the research questions an experiment is conducted where two identical mobile games
are built, one according to OOD and the other to DOD to collect empirical quantitative data
and compare the results. The study limits the scope by running the games on Android mobile
phones.
The results of comparing the CPU Usage show significant differences especially when the
amount of data is large. For instance, in the DOD version of the game,the CPU spends 20.9%
of the time on updating data, while it spends 69.2% of thetime on the same action in the OOD
version of the game.
No significant differences are observed regarding the total Memory allocated for the games in
both versions. It can therefore be concluded that when the number of objects/data is big, a
more optimized code should be written following the Data oriented Design approach with
regard to better CPU and Memory Usage and better game performance.
Keywords
Mobile games, Object-Oriented Design, Data-Oriented Design, Game performance, CPU
Usage, Memory Usage.
2
Contents
1 Introduction ............................................................ 1
1.1 BACKGROUND ............................................................................................... 1
3
Contents
4.1.1
Findings. .......................................................................................... 21
4.1.2 Analysis
.................................................................................................................................................. 21
4.2 MEMORY ........................................................................................................... 24
4.2.1
Findings. .......................................................................................... 24
4.2.2 Analysis
.................................................................................................................................................. 24
5.2.1 Discussion of first research question: “How does the CPU Usage differ in the two
approaches?” .........................................................................................................................................................
27 5.2.2 Discussion of second research question: “How does the Memory Usage differ in the
two approaches?”
......................................................................................................................................................... 28
5.3 CONCLUSIONS .................................................................................................... 28
6 References .......................................................... 30 7
Appendices...........................................................32
4
1 Introduction
The chapter provides a background for the study and the problem area the study is built upon. Further, the
purpose and the research questions are presented. The scope and delimitations of the study are also described.
Lastly, the disposition of the thesis is outlined.
Recently, mobile games played an important role in the entertainment industry, an increased
number of people play games using their mobile phones. According to statistics, there are
2.3 billion mobile gamers who play mobile games more than 10 times per week (Cough,
2020). This increased number of mobile gamers gives the opportunity to develop more
mobile games.
As mobile phones get newer and better in both design and functionality, processor sizes and
memory capacity, mobile games development requires increased development quality to
utilize the modern phones abilities and to improve game performance (Hammershoj,
Sapuppo, & Tadayoni, 2010). A gamer enjoys the game most when it has fast interactions
which make the game real and exciting, that is why the performance of the game is something
essential for the developer to consider.
Developing good games requires special optimization for choosing the right design approach
to write the code accordingly (Inam, Malik, Sabahat, & Subhani, 2017). This is especially
crucial in mobile games development, because of the scarce resources on mobile devices,
such as the small memory, CPU, small screen size, limited battery life etc. (Zhang, Han,
Kunz, & Hansun, 2007).
This student thesis aims to investigate whether any significant performance improvements
can be achieved by developing mobile games with a Data-Oriented Design as opposed to an
Object-Oriented Design.
1.1 Background
Object-oriented design (OOD) approaches have been a default approach when developing
games as Nystrom mentions in his book (Nystrom, 2014). The main idea of the approach is
centered on defining, producing and operating on objects. Every object has its state and
behavior that builds the functionality of the object (Mines, 2018).
Object Oriented Programming allows us to write code that is close to reality, thinking of
real objects that have their own properties and interact with other objects.
Data-oriented design (DOD) is a different way to approach program design and it is used in
game development (Fabian, 2018). DOD focuses on data and how it is transformed and used
so that the functionality and the data are separated, and they are no longer coupled to a
specific object (Llopis, 2009).
From previous research, there is no literature that makes a direct comparison between the
OOD and DOD approaches regarding their effect on the performance of the games. Several
1
theoretical perspectives state that DOD is a better choice when developing games, for
example; Mike Acton (2014) describes DOD as the design that fits the hardware it runs on it,
Fabian (2018) ensures that designing the game the DOD way will support locality of
references and minimize fetching of unnecessary data and Mike Gieg (2019) encourages to
convert the game design to DOD whenever good performance is the goal, but still an
investigation is needed to collect quantitative data that shows convincing results.
In this thesis, an investigation about how the two approaches affect the game performance is
done, where two games are developed; the first one with an Object Oriented Design
approach using the traditional Unity 3D game engine, and the second one with Data
Oriented Design approach using Unity’s new Data oriented game engine DOTS.
To evaluate the game performance, the CPU usage and the memory usage is measured for the
two identical games.
2
On the left, we have the OOD way of defining 3 objects of class Particle every object has x,
y, and color properties (attributes). On the right the DOD way has one class
ParticleManager that includes an array of all x, y, and color attributes’ values.
And in memory the two ways of structuring the data look significantly different.
Figure 2 illustrates how the properties of the three Particle objects are structured in memoryon
the other hand how gathering the same type properties in one group in the DOD way
structures the data sequentially.
Object-oriented design allows us to think about objects as real entities, a human mind can
reason about how data would be used together and therefore be structured accordingly in
memory, but in fact compilers cannot infer and predict about how objects are designed and
will be used because they do not have the intelligence to do that yet especially when the objects
have a large number of attributes. This would explain why there is no compiler yet that can
interpret the Object-oriented code to a Data-oriented code.
OOD and DOD have different ways of defining and structuring data, however, how
significant performance differences there may be between developing a game with OOD
and DOD approaches are yet to be determined.
The problem of the study is that there have not been done documented studies that directly
compare mobile games development based on how the different ways of structuring the
data in the OOD and DOD approaches result in better CPU Usage and Memory Usage.
The way data is structured in memory affects the overall performance of the game. The
OOD and DOD approaches have different ways and priorities to consider about while
coding. Consequently, to understand how these differences can have different effects on
3
the game performance, it is necessary to conduct an experiment. Hence, the purpose of the
study is:
To investigate the performance differences between Data-oriented design (DOD) and Object-oriented design (OOD) approaches in
Mobile games.
1.4 Delimitations
The study limits the scope of the project by developing two games for mobile phones where
the focus will be on performance related issues, namely measuring the CPU and memory
usage. To avoid introducing variables that may affect the performance and the memory
capacity, the test cycle runs automatically with no user input required. This ensures an
identical cycle lifetime for each test cycle.
The time spent on developing the two games with the two different versions is not
measured, because the developers are more familiar with the Object-oriented programming
and cannot claim that Data-oriented programming takes longer time to develop.
1.5 Definitions
CPU Cache: The CPU Cache is a small but very fast memory located near the Central
Processor Unit (CPU), which executes the instructions of any program running on the
device. CPU Cache’s task is to hold data from frequently visited memory locations in orderto
reduce the number of cycles to the main memory every time that data is needed to be accessed.
Modern hardware use multi-level caches (L1,L2,..) where accessing the first level
/layer is the fastest (Carvalho, 2002).
Cache hit: When a program (an application) requests data, the CPU first looks for the data at
the CPU cache if it finds the requested data a cache hit occurs. A cache hit means that data
delivered the fastest way. (Nishry, 2015).
Cache miss: In oppose to cache hit, a cache miss is when the CPU can’t find the requested data
in the CPU cache and a longer journey to main memory is needed. (Nishry, 2015).
Locality of reference: the multilevel cache systems in modern CPUs provide for
exploitation of the locality of reference. As described in Encyclopedia of Parallel Computing
“The term locality of reference refers to the fact that there is usually some predictability in
the sequence of memory addresses accessed by a program during its execution” (Padua, 2011).
Restructuring the code can enhance the locality of reference so that a large number of data
accesses is done from the CPU cache and a small number is accessed from the main memory.
4
Multithreading: As defined by Techopedia: Multithreading is a type of execution model that
allows multiple threads to exist within the context of a process such that they execute
independently but share their process resources. Multithreading if programmed correctly,
ensures faster execution time because it utilizes the multicore processor the best way
(Techopedia, 2017).
1.6 Outline
The thesis is structured as follows: Chapter 2, methodology, gives an overview about the
methods chosen to conduct the study with as well as describes the game design. Chapter 3 is
the theoretical framework which gives an overview about pervious research and describes the
theory behind the study. Chapter 4 provides an overview and description of the empirical
data extracted from the study. Chapter 5, Analysis, answers to the research questions by
analyzing collected empirical data and the theoretical framework. Finally, chapter 6,
discussion and conclusions, provides a summary description of the study’s results,
furthermore, it concludes the study and gives suggestions for future work
5
Theoretical background
2 Theoretical background
Carvalho (2002) discusses the potential gap between CPU and memory usage (see
figure 3). He encourages us to utilize the CPU cache the right way by understandingthe
memory hierarchy and memory access patterns to write a more cache friendlycode.
Nystrom (2014) underlines the importance of writing cache friendly code while game
developing and ensures that data and the way it is structured can affect the game
performance. Furthermore, he shows some code samples to explain the idea of
writing a cache friendly code. He does not mention about two different approaches of
designing games, but rather he calls them two different ways of coding (Nystrom,
2014).
From the readings, we recognize that there is a need to compare the two different
approaches by applying them on two identical mobile games to get good and
convincing results.
In our study, an Android mobile phone is used, and the CPU and Memory usage are
measured to understand to what degree the performance is affected by using the
different design approaches.
6
Theoretical background
In the following sections, the theory providing the theoretical foundation for
answering the research questions is described.
7
Theoretical background
behavior (methods) when creating the Lion class, but a Lion class inherits the Cat
class.
Abstraction: Abstraction refers to work with something you know how to use but
you don’t know how it works internally. For example, saving elements to a file
without knowing how the file sorts them (as an array, as a list etc.). This principle
helps with code reusability and flexibility because by writing code with abstract data
structures, programs that do a specific task, define an interface which can be reused by
several different subprograms to fulfill different tasks.
Object Oriented Programming stores data in stack and heap memory. In the stack
method-related information is stored, such as the local variables, parameters and
returned addresses. In the heap application-related information is stored, namely the
Objects with all their attributes (Rahman, 2013).
Using the heap is flexible because the size allocated can be modified. The problem is,
the heap memory is allocated randomly, which means that objects instantiated after
each other can be placed in random places on the heap and this would be
inadequate for good exploitation of locality of reference. In (Janardhanan & Barrett,
2017) it was noted that poor allocation of memory leads to poor memory
management and ineffective usage of CPU power.
Another issue in OOD is when an object is fetched from the heap, all the attributes
belonging to that object are fetched even though when some of them would be used or
one of them, this would take lots of place on the CPU cache when the number of
objects is big and it would greatly affect the performance because there would
8
Theoretical background
not be enough space left on the cache line for other data so the number of cache
misses will increase and longer journeys to main memory will be required.
Motivated by the CPU-Memory speed gap problem (see figure 3), Data-oriented
Design was introduced. DOD is a programming paradigm with focus on data and
cache coherency (Wikipedia, 2020). It is especially used in video games development
where the delays caused by cache misses can affect the game performance
(Davidovic´, 2014).
When a class owns some data, to some extends, it limits the reusability of that data, and
when a function will be added to only a specific piece of data in that class, different
and sometimes unrelated data need to be added, and this results in many additional
data that are hard to untangle because the function will need to drag in them from
random places from the class (Fabian, 2018).
Efficient cache usage: DOD attempts to structure data that are used at the same
time in one group. For example: Instead of having a “Car” object with “Engine”
and “Horn” attributes coupled together, the attributes are separated because they
are rarely used at the same time so that when the “Engine” needs to be updated,
there is no need to fetch the “Horn” attribute. This would take less space on the
cache line and will therefor reduce the cache misses. In addition, this would makethe
CPU work less, because instead of searching for all the “Engine” attributes on
random addresses, it will find them grouped together in contiguous memory blocks.
9
Theoretical background
CPU Usage refers to the term that describes how much work the processor is doing.
It varies depending on the tasks performed by the CPU (Easey, 2020). It is important
to monitor the CPU usage because it is a primary indicator to all applications’
performance including games. CPU Usage is measured in clock speeds indicated in
Hertz or cycles per second. If the CPU Usage is high, probably a performance issue will
arise, and the frame rate will decrease. Although modern devices have multicore
processors which can greatly deal with multitasking, where several processors work
simultaneously with different kind of tasks, abnormal CPU Usage situation can still
occur (Intel, 2020).
Memory Usage means the amount of memory available on the system, and the
memory already in use by all the applications on the device (Wiki, 2020). Memory
utilization is the average utilization derived from the percent of available memory in
use at a given moment. Monitoring the memory usage helps to discover memory
leak. When memory utilization is increased, it may indicate to memory deallocating
problems which in turn can cause performance issues. High memory usage can over
time make the device unresponsive to its tasks (Engine, 2020).
GameObjects
A Gameobject is an object containing references to monobehaviour components.
10
Theoretical background
Monobehaviour components
A monobehaviour component contains data and logic coupled together.
The Monobehaviour component typically has some variables containing data and an
update function which performs operations on this data each frame. In this example
(see table 1) the position data of the transform component is incremented by a
given vector multiplied by the speed data and the time between the current and
previous frame.
1 public class Cube: MonoBehaviour
2 { public float
3 speed; void
4 Update()
5 {
7 }
8 }
9
Table 1: An example of a Monobehaivor class
2.7.2 DOTS
It consists of three main elements, also referred to as the three pillars of DOTS;
The ECS, The C# Job System and The Burst Compiler.
The definitions of the different concepts are according to Unity’s official website
(Unity, DOTS, 2020)
11
Theoretical background
2.7.2.1 ECS
Entities
Components
A component contains data and only data. Unlike the classical Unity, where a
component is owned by a gameobject, a component in ECS is not owned by an
entity but it is independent and only loosely coupled to an entity by an id reference.
This allows components of the same type to be structured next to each other in
chunks in memory which in turn increases cache hit rate and allows for
multithreading by the C# Job system. Table 2 shows an example of declaring a
component.
2 { public float
3 speed;
4 }
12
Theoretical background
Systems
Contains logic and only logic. Systems governs the behavior of entities by operating
on component data.
In the following example, the “MoveSystem” iterates all entities that have
“Translation” and “Cube” components and updates the position data of the
Translation component by the speed data of the Cube component each frame.
In contrast to classical Unity where each component containes its own update
function, now there is a single function that updates all components. Table 3
shows an example of a System.
2 {
4
{
5
Entities
6
7 .WithName("MoveSystem")
.ForEach((ref Translationposition, ref Cube cubeData) =>
8
{
9 position.Value += math.forward * cubeData.speed *
Time.DeltaTime;
10
11 })
12 .ScheduleParallel();
}
}
Table 3: System in ECS
The problem is that it can be quite difficult and complex to do this in a safe way,
which is what
13
Theoretical background
Unity uses something called Mono for scripting which can compile C# code to
different platforms to make it easy to create multi-platform games. The drawback of
this is that this is much slower compared to native code for specific platforms Burst
is a compiler, primarily designed to work with the C# Job system, that solves this
problem by translating from C# code to highly optimized native code to improve
performance.
14
Method and implementation
A literature review has been done to collect information and state clear definitions
about the OOD and DOD approaches.
In the study two identical games developed with OOD and DOD approaches built
the test ground for the experiment.
• To answer the first research question the CPU Usage of the developed
games is monitored and analyzed.
• To answer the second research question the Memory Usage of the developed
games is monitored and analyzed.
3.2 Hypothesis
A game built in Unity’s DOTS gives better CPU Usage and Memory Usage than
a game built in traditional Unity3D.
The study has this hypothesis because Data Oriented Design was implemented to
improve the speed gap between the memory and CPU. In addition, as stated by
Unity’s official website the new technology DOTS ensures better CPU utilization
because it supports multithreading by its architecture ECS.
In the early stage of the study, a literature review for previous research about Object
Oriented Design and Data Oriented Design in the game development area was
initiated. The literature review phase helped the authors to formulate the research
questions as well as to identify the hypothesis.
Throughout the experiment phase, the study followed guidelines from the book
“Writing for Computer Science” (Zobel, 2014). According to the book, the first
thing to consider about when designing experiments in Computer Science is to
identify the baseline, that is the benchmarks against which the contribution would
be measured. The baseline in our experiment is implemented by the authors, it is
15
Method and implementation
the game built in the traditional Unity3D. The baseline is appropriate because
Unity3D has a pure Object-Oriented Design that would help to build the game
according to an Object-Oriented approach.
In the next step, the authors decided to look at the CPU Usage and Memory Usage
for the two games, as they are essential metrics to monitor when game development
in order to ensure good performance.
The idea of the game is original and inspired by the state-of-art and theoretical
foundations that shows that DOD results in better CPU and Memory utilization.
Hence the goal of the game is:
To test how the CPU handles the increasing number of objects rotating on the
screen simultaneously.
To test how structuring the data in contiguous blocks in memory improves memory
utilization
To achieve the goal, the game consists of a single scene in which 3D cubes are
spawned. These cubes then move up and down while rotating around their own
axis. As the game starts, the “roundCounter” variable is set to 10 and a spawning
loop is initiated. With every iteration of the spawning loop, 5000 cubes are
instantiated in the scene and the roundCounter is decremented by 1. After a delay
of 50 frames the loop continues. The reason the delay is set in frames and not in
seconds is to ensure an equal number of frames being monitored for both versions
of the game.
Having the delay in seconds would mean fewer number of frames would be
monitored each second over the game's lifetime, due to increased processor load as
the number of cubes are increased. The iteration continues until the roundCounter
reaches zero and there is a total of 50 000 cubes in the scene at which time the game
terminates.
16
Method and implementation
In the OOD version of the game, a gameobject in the scene with a “Spawner”
component is responsible for instantiating cube gameobjects in the scene, from a
prefab (template gameobject). The cube object has a move component attached that
moves the cube, and a rotate component, which rotates the cube.
17
Method and implementation
The DOD version of the game is very similar to the OOD version. In this version,
the “Spawner” object creates cubes as entities instead of gameobjects. The entities
are created from an archetype, which is basically a template for the entity, describing
what components it consists of, similar to the prefab in OOD version.
These cubes are then moved and rotated by the “MoveSystem” and the
“RoateSystem” systems respectively.
The data collection consists partly of studying literature and partly of collecting
quantitative data.
The empirical data from the experiment are real data collected from Unity’s profiler
window at game execution time. More precisely, data will be collected by taking the
mean of 20 frames for each time the number of cubes is increased by 5000.
The profiler window is a tool used by developers to profile different aspects of the
game’s performance.
For our study’s purpose the CPU Profiler and Memory Profiler are used. To collect
information about how much time is spent on tasks of different categories e.g.
rendering, scripts and animations, on every frame, the CPU Usage Profiler is used
(Unity, CPU Usage Profiler, 2019). The Memory profiler tool is used to capture,
inspect and compare memory snapshots by giving an overview of memory
allocations in order to reduce memory usage whenever needed in the game (Unity,
Memory Profiler, 2020).
18
Method and implementation
Because the study is investigating both the CPU Usage and Memory usage
differences between the games, two different T-tests are done to check how
significant is the differences between the collected data sets.
H1: There is a difference between the game built in DOTS and the game built in
Unity3D regarding the CPU Usage.
H1: There is a difference between the game built in DOTS and the game built in
Unity3D regarding the Memory Usage.
Every T-test has a p-value, that is the probability that the results from the
experiments happened by chance. A low p-value indicates that the result is valid,
this means, the difference is actually significant between the two data sets and the
result could be generalized and the null hypothesis can be rejected because the
alternative hypothesis is more probable (Walpole, 2016).
The limit to consider a p-value as low varies, in this thesis thou, the limit is at p ≤
0.05 for the both T-tests, because it is a common p-value (Gunnarsson, 2003).
The calculation of the T-test is done on Excel to ensure accurate calculations as the
number of items in every data set is big.
A probable risk when writing code in two different paradigms is that the developer
is most likely more competent with one of them and will therefore write better and
more optimized code for that paradigm and the gap in code quality will likely grow
the more complex the application gets. To alleviate this issue and to ensure the
19
Method and implementation
validity of the results, the developers took an online course via Udemy to educate
themselves about the Data-Oriented Design in game development
Further, games can be very complex and messy collections of code with a multitude
of different things that might affect performance and in conducting an experiment
like this, it can be difficult to pinpoint the exact causes of disparities in performance,
To avoid this problem, the games for this experiment are designed to have as few
variables as possible. This ensures, to the extent possible, that any potential
disparities in performance measured, are not a reflection of the developer’s aptitude,
but rather, of the underlying system’s ability to process data.
By designing the games with only the bare minimum code necessary to meet the
target objectives, a fair comparison between the traditional Unity3d game engine
and Unity3d DOTS can be accomplished.
20
Discussion and conclusions
4.1 CPU
To answer the first research question” How does the CPU Usage differ in the two
approaches?”, the CPU Usage profiler is monitored every frame, Data is collected
by taking the mean of 20 frames for each time the number of cubes is incremented
by 5000.
4.1.1 Findings
Figure 9: Average time in milliseconds it takes to render one frame for DOD and
OOD version respectively.
4.1.2 Analysis
The second most time, 20.9%, is spent in the update function, iterating all the cubes
in the scene and updating their data. This can be contrasted with the OOD version
where as much as 69.2% of the time is consumed by the update function, as shown
21
Discussion and conclusions
in Figure 11. Here, no time is spent waiting for the GPU, which is a clear indicator
of the CPU being the bottleneck.
22
Discussion and conclusions
Along with the graphs that shows the performance differences, and are in line with
the literature that suggests that DOD is especially good at handling large numbers
of object, a significance analysis in form of T-test is done in order to submit that
there is really a significance differences between the CPU Usage in the two
approaches.
Figure 13 shows, when applying the T-test, a p value at 0.00017 is yielded and it is
less than 0.05. In addition, if t Stat < -t Critical two-tail or t Stat > t Critical twotail,
the null hypothesis is rejected. Furthermore, the mean difference is significantly big.
23
Discussion and conclusions
it can therefore be concluded that there is a significant difference in CPU usage and
the Ho for the first T-test can be rejected because H1 is more probable to be true.
4.2 Memory
To answer the second research question” How does the Memory Usage differ in
the two approaches?”, the Memory profiler is monitored every frame. Data is
collected by taking the mean of 20 frames for each time the number of cubes is
incremented by 5000.
4.2.1 Findings
Figure 14: The total amount of memory in megabytes used by the application
for the DOD- and OOD version respectively.
When looking at Figure 14, any real memory issues could be observed. Both
versions stay below 200 MB in allocated memory which is well within reasonable
bounds even for older mobile phones.
4.2.2 Analysis
Figure 14 shows that OOD uses less memory at the start but has a relatively steep
trendline which suggests a significant increase in memory usage per cube in the
scene.
DOD on the other hand uses more memory at first but has a gentler trendline. The
amount of memory used for each new cube seems to be less than OOD. We see
this in figure 17. The reason for the large amount of memory used at the beginning
could possibly mean that it pre allocates memory. This is a bit unclear, however,
and should be investigated further.
24
Discussion and conclusions
Another interesting observation can be found when breaking down memory usage
and looking only at the parts that are related to the cubes. In the case of DOD all
cube related data is stored sequentially as arrays (see figure 15). For OOD the
different parts of the cube, as shown in Figure 16, are stored randomly as objects.
Figure 15: Cube related memory Figure 16: Cube related memory
consumers DOD consumers OOD
By dividing the total amount of memory used by all cube components by the number
of cubes, a value of memory usage for each cube can be estimated.
As seen in Figure 17, OOD requires around five times as much memory for each
cube, approximately 1000 bytes, to DOD:s approximately 200 bytes.
Although there is no big difference in memory allocated for every game, a T-test is
conducted to submit whether the difference was due to chance or not.
25
Discussion and conclusions
This chapter summarizes the results of the study. Further, it discusses the choice of method and the
findings of the study. It also describes the conclusions and recommendations of the study. Suggestions
for further research are given at the end of the chapter.
The student thesis started with narrowing down the ideas that the authors had to
focus on one specific problem and to have one specific goal with the work.
At the beginning, an intensive research on related topics were done, where keywords
such as mobile games development, OOD and DOD were used. The relevant
articles or web sites were gathered in a shared document between the authors to
facilitate the searching process. Unfortunately not so many peer-reviewed papers
nor books were found about Data-oriented design in game development, but rather
26
Discussion and conclusions
the needed information was gathered from one book, experienced game developers’
blogs, and an online course from Udemy with the name “Unity’s DOTS
fundamentals” was useful to buy to get more familiar with coding the DOD way.
In conducting the experiment and designing the games, the main goal was to achieve
the objectives and see the performance differences in the CPU and Memory Usage
between both versions of the games. For this reason, the game design focused
mostly on having the minimum code/data needed to reduce the side causes that
may affect the performance and the validity of the results. To meet the requirements
of reliability, the code base for the games are available on GitHub and a link is
shared as an appendix.
In the data collection phase, one Android mobile phone was used to play the game
with and collect the data sets. More supporting results could be gathered if the
games were played on one more mobile phone that has a different processor size
and memory capacity to see how different processors could handle the increasing
number of data. The main reason was that it would be time consuming, and no
additional Android mobile phone was available.
The data analysis phase went as planned. The collected data were analyzed in an
accurate way with help of charts, graphs, and a significance analysis in form of Ttest.
To investigate the performance differences between Data-oriented design (DOD) and Objectoriented
design (OOD) approaches in Mobile games.
Our approach to finding the best way to fulfill the purpose of the study, was to
conduct an experiment, where two identical games were developed according to
DOD and OOD approaches respectively and compare the CPU and Memory
performance. By doing this, we made some findings that we think will contribute
to the mobile game development field of research.
5.2.1 Discussion of first research question: “How does the CPU Usage differ in the
two approaches?”
Figure 10 and Figure 11show clear answer to the first research question. The CPU
Usage differ in the two approaches, different percentages of time are consumed by
the same activities (waiting for the GPU, updating the cube data and rendering the
cubes) in the two versions of the game. To pinpoint the exact reasons for this
discrepancy and explain why the OOD version requires so much more time to
update the data, which is the most time consumer activity, further experimentation
would be required. From the theory, however, we can summarize:
The ECS that has a Data-oriented design runs a single update function for all
components and iterates over all data. In the Classical Unity, that has an
27
Discussion and conclusions
Objectoriented design the update function runs for every object. For example, in
our experiment, the OOD game runs 50000 update functions by the end of the
game, while the DOD runs one update function and iterates it 50000 times. In
addition, ECS has built-in functionality by default, therefore the Systems in ECS
will update entities faster than MonoBehaviours updating GameObjects in Classical
Unity.
The DOD requires less CPU cycles, as the CPU needs to look at only two memory
addresses: the function and the base address for the chank of data. In addition, it
utilizes the cache more effectively since data is stored in sequential memory blocks,
rather than randomly in the OOD way, and it fully utilizes the C# Job System and
enables multithreading and parallelization.
5.2.2 Discussion of second research question: “How does the Memory Usage differ in
the two approaches?”
From theory, possible reasons to explain this big difference in memory allocated for
every cube in the both versions could be that DOTS use Structs of Arrays instead
of classes. Structs are value types and when dealing with Structs it is directly dealing
with the underlying data and a single space is allocated in memory to store the value,
while in Classes which are reference types, it is dealing with references, and spaces
for the value and its reference are allocated in memory. Structs are allocated either
on the stack or inline in contiguous memory blocks, while Classes are allocated
randomly on the heap. Therefore, allocation and deallocation of value types arrays
are cheaper and faster than reference types.
Further, the components used in Classical Unity inherit from a “Monobehaviour” class
which in turn inherit from another class. Each class in this inheritance chain has its own
data and logic attached to it which needs to be stored in memory. In Dots the components
are simple structs containing only the data that is needed for that component.
28
Discussion and conclusions
5.3 Conclusions
Throughout this project, two games have been developed to compare the CPU and
Memory Usage and to investigate how they affect the game performance. The
results indicate that writing optimized code, with focus on memory-layout and data
structure, can improve the CPU Usage especially when the processor will perform
on large data.
However, it cannot be completely attributed that the improvement was solely due
to the underlying game design, DOD. The use of ECS architecture implemented in
DOTS established separation between data and logic and enabled implementation
of data-oriented principles, so a pure DOD solution was not achieved.
This student thesis has a contribution in the researches about game development
where there is lack of comparative studies (OOD vs DOD) had been done.
29
Discussion and conclusions
of more complete games with GUI and players to be able to make more reliable
conclusions about the difference in performance between OOD and DOD.
30
References
6 References
Askarbekuly, N., Fedoseev, K., Mazzara, M., & Uzbekova, E. (2020, 07). A Case Study on
Object-Oriented and Data-Oriented Design Paradigms in Game Development.
Retrieved from Research Gate:
https://www.researchgate.net/publication/342735514_A_Case_Study_on_ObjectOri
ented_and_Data-Oriented_Design_Paradigms_in_Game_Developmen
Carvalho, C. (2002). The gap between processor and memory speeds. (pp. 27-34). Braga
Portugal: IEEE International Conference on control and automation.
Cohen, W. (2016, 03 01). Reducing Memory Access Times with caches. Retrieved from Red
Hat: https://developers.redhat.com/blog/2016/03/01/reducing-memory-
accesstimes-with-cac
Cough, C. (2020, 09 11). Portion of mobile gamers worldwide. Retrieved from Statista:
https://www.statista.com/statistics/748089/number-mobile-gamers-worldplatform/
CppCon. (2014, 09 30). CppCon 2014: Mike Acton "Data Oriented Design and C++".
Retrieved from YouTube: https://www.youtube.com/watch?v=rX0ItVEVjHc&t=3s
Davidovic´, D. (2014, May 28). What is Data-Oriented game engine? Retrieved from
envatotuts+: https://gamedevelopment.tutsplus.com/articles/what-is-data-
orientedgame-engine-design--cms-21052
Engine, M. (2020). Memory Utilization Monitor. Retrieved from Manage Engine OpManager:
https://www.manageengine.com/network-monitoring/memory-monitoring
Hammershoj, A., Sapuppo, A., & Tadayoni, R. (2010). Challenges for Mobile application
development. 2010 14th International Conference on Intelligence in Next Generation
Networks (pp. 1-8). Berlin-Germany: IEEE.
Inam, H., Malik, A. A., Sabahat, N., & Subhani, A. (2017). Improving the process for mobile
game development. 2017 International Conference on Communication Technologies
(ComTech) (pp. 45-49). Rawalpindi-Pakistan: IEEE.
Intel. (2020). How to Fix High CPU Usage. Retrieved from Intel: http://www.intel.com
31
Janardhanan, D., & Barrett, E. (2017). CPU Workload forecasting of machines in data centers
using LSTM recurrent neural networks and ARIMA models. The 12th International
Conference for Internet Technology and Secured Transactions (ICITST) (pp. 55-60).
Cambridge, UK: IEEE.
Joshi, R. (2007). Data-Oriented Architecture: A loosely coupled Real-Time SOA. RTi, 1-54
.
References
Llopis, N. (2009, December 04). Data-Oriented Design (Or why you may be shouting
yourself in the foot with OOP). Retrieved from Games
from within:
http://gamesfromwithin.com/data-oriented-design
Omankwu, Chinecherem, O., Nwagu, Chikezie, K., & Inyiama, H. (2018). Computer Science
Research Methodologies. International Journal of Computer Science and Information
Security (IJCSIS), 142-144.
Rahman, M. (2013). In M. Rahman, Expert C# 5.0 with .NET 4.5 Framework (pp. 85-108).
Berkeley CA: Apress.
Unity-ANZSEA. (2019, 06 24). Converting your game to DOTS-Mike Gieg. Retrieved from
YouTube: https://www.youtube.com/watch?v=Gs19-JMvyxc
Walpole, R. E. (2016). Probability and statistics for engineers and scientists. Upper Saddle
River : Pearsn.
Zobel, J. (2014). Experimentation. In J. Zobel, Writing for Computer Scienece Third edition
(pp. 197-215). London: Springer.
Search terms
7 Appendices
• Appendix 1: Mobile phone specification.
Motorola MOTO G8 POWER
CPU Octa-core (4x2.0 GHz Kryo 260 Gold & 4x1.8 GHz Kryo 260 Silver)
eMMC 5.1
• Appendix 2: The GitHub Repository link for the code of the OOD game.
https://github.com/bjerra/Unity-Classic-CubeTest
• Appendix 3: The GitHub Repository link for the code of the DOD game.
https://github.com/bjerra/Unity-DOTS-CubeTest
33
Postadress: Besöksadress: Telefon:
Box 1026 Gjuterigatan 5 036-10 10 00 (vx)
551 11 Jönköping
Postadress: Besöksadress: Telefon:
Box 1026 Gjuterigatan 5 036-10 10 00 (vx)
551 11 Jönköping