# Data-oriented design

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Data-oriented_design
> Markdown URL: https://mediated.wiki/source/Data-oriented_design.md
> Source: https://en.wikipedia.org/wiki/Data-oriented_design
> Source revision: 1330544974
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Program optimization approach in computing}}
{{Distinguish|Data-driven programming}}
{{More citations needed|date=July 2020}}
In [computing](/source/computing), '''data-oriented design''' is a [program optimization](/source/program_optimization) approach motivated by efficient usage of the [CPU cache](/source/CPU_cache), often used in [video game](/source/video_game) development.<ref name="Llopis">{{cite web|url=http://gamesfromwithin.com/data-oriented-design|title=Data-oriented design|last=Llopis|first=Noel|date=December 4, 2009|website=Data-Oriented Design (Or Why You Might Be Shooting Yourself in The Foot With OOP)|archive-url=|archive-date=|access-date=April 17, 2020}}</ref> The approach is to focus on the data layout, separating and sorting [fields](/source/field_(computing)) according to when they are needed, and to think about transformations of data. Proponents include Mike Acton,<ref>{{cite web|title=CppCon 2014: Mike Acton "Data-Oriented Design and C++"|website = [YouTube](/source/YouTube)| date=29 September 2014 |url=https://www.youtube.com/watch?v=rX0ItVEVjHc}}</ref> [Scott Meyers](/source/Scott_Meyers),<ref>{{cite web|title=code::dive conference 2014 - Scott Meyers: Cpu Caches and Why You Care|website = [YouTube](/source/YouTube)| date=5 January 2015 |url=https://www.youtube.com/watch?v=WDIkqP4JbkE}}</ref> and [Jonathan Blow](/source/Jonathan_Blow).

The [parallel array](/source/parallel_array) (or [structure of arrays](/source/structure_of_arrays)) is the main example of data-oriented design. It is contrasted with the ''array of structures'' typical of object-oriented designs.

The definition of data-oriented design as a [programming paradigm](/source/programming_paradigm) can be seen as contentious as many believe that it can be used side by side with another paradigm,<ref>{{cite web|access-date=2023-12-20|title=Data-Oriented Design|author=Richard Fabian|date=October 8, 2018|url=https://www.dataorienteddesign.com/dodbook/|website=www.dataorienteddesign.com}}</ref> but due to the emphasis on data layout, it is also incompatible with most other paradigms.<ref name="Llopis"/>

== Motives ==
These methods became especially popular in the mid to late 2000s during the [seventh generation of video game consoles](/source/seventh_generation_of_video_game_consoles) that included the [IBM](/source/IBM) [PowerPC](/source/PowerPC) based [PlayStation 3](/source/PlayStation_3) (PS3) and [Xbox 360](/source/Xbox_360) consoles. Historically, [game console](/source/game_console)s often have relatively weak [central processing unit](/source/central_processing_unit)s (CPUs) compared to the top-of-line desktop computer counterparts. This is a design choice to devote more power and [transistor budget](/source/transistor_budget) to the [graphics processing unit](/source/graphics_processing_unit)s (GPUs). For example, the 7th generation CPUs were not manufactured with modern [out-of-order execution](/source/out-of-order_execution) processors, but instead use [in-order processor](/source/in-order_processor)s with high clock speeds and deep [pipelines](/source/Pipeline_(computing)). In addition, most types of computing systems have [main memory](/source/main_memory) located hundreds of [clock cycle](/source/clock_cycle)s away from the [processing element](/source/processing_element)s. Furthermore, as CPUs have become faster alongside a large increase in main memory capacity, there is massive data consumption that increases the likelihood of  [cache misses](/source/cache_misses) in the [shared bus](/source/system_bus), otherwise known as [Von Neumann bottlenecking](/source/Von_Neumann_architecture). Consequently, [locality of reference](/source/locality_of_reference) methods have been used to control performance, requiring improvement of [memory access pattern](/source/memory_access_pattern)s to fix bottlenecking. Some of the software issues were also similar to those encountered on the [Itanium](/source/Itanium), requiring [loop unrolling](/source/loop_unrolling) for upfront scheduling.

== Contrast with object orientation ==
{{Original research section|date=September 2021}}
The claim is that traditional [object-oriented programming](/source/object-oriented_programming) (OOP) design principles result in poor data locality,<ref>{{cite web
 | title = INTEL ® HPC DEVELOPER CONFERENCE FUEL YOUR INSIGHT IMPROVE VECTORIZATION EFFICIENCY USING INTEL SIMD DATA LAYOUT TEMPLATE (INTEL SDLT)
 | url = https://www.intel.com/content/dam/www/public/us/en/documents/presentation/improving-vectorization-efficiency.pdf
}}</ref><ref>{{cite journal
 | title = SoAx: A generic C++ Structure of Arrays for handling particles in HPC codes
 | author1 = Holger Homann
 | author2 = Francois Laenen
 | journal = Computer Physics Communications
 | date = 2018
 | volume = 224
 | pages = 325–332
 | doi = 10.1016/j.cpc.2017.11.015
 | arxiv = 1710.03462
 | bibcode = 2018CoPhC.224..325H
 | s2cid = 2878169
 | language = English
}}</ref> more so if runtime polymorphism ([dynamic dispatch](/source/dynamic_dispatch)) is used (which is especially problematic on some processors).<ref>{{cite web|title=What's wrong with Object-Oriented Design? Where's the harm in it?|url=http://www.dataorienteddesign.com/dodmain/node17.html}}describes the problems with virtual function calls, e.g., i-cache misses</ref><ref name="Llopis"/> Although OOP appears to "organise code around data", it actually organises [source code](/source/source_code) around [data type](/source/data_type)s rather than physically grouping individual fields and arrays in an efficient format for access by specific functions. Moreover, it often hides layout details under [abstraction layer](/source/abstraction_layer)s, while a data-oriented programmer wants to consider this first and foremost.

== See also ==
* [CPU cache](/source/CPU_cache)
* [Data-driven programming](/source/Data-driven_programming)
* [Entity component system](/source/Entity_component_system)
* [Memory access pattern](/source/Memory_access_pattern)
* [Video game development](/source/Video_game_development)

==References==
{{Reflist}}

{{Programming paradigms navbox}}

Category:Software optimization
Category:Video game development
Category:Programming paradigms

---
Adapted from the Wikipedia article [Data-oriented design](https://en.wikipedia.org/wiki/Data-oriented_design) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Data-oriented_design?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
