Daab – A Rust Crate for Managing Data Dependencies

Managing data dependencies between logical units of a software can become really painful. The more complex the system becomes, the more difficult it is to take care of updating dependent units when data change. We also had this problem at an early stage in the development of our Sphere Engine, so we decided to make a Rust crate dedicated to exactly this problem.

Let’s say we want to compute the sum of two integers a and b. How would we ensure that this sum is updated when a or b updates? The most obvious way would be to actually only compute the sum when it is needed. This works here as computing a sum of two integers is a really lightweight task, but one can easily imagine that a more complex task would be too time-intensive to be computed again and again, even if it doesn’t have to. This becomes even more of a problem when looking towards projects that need to be realtime capable, such as a video game, for example. So we need to find a different solution. What if we could cache the result and the return it on demand and only re-compute it when necessary? This is exactly the idea of daab. Let’s look at the following piece of code:

As you may know, we’re working on our own graphics engine, the “Sphere Engine”. Such an engine is a complex piece of software, and with any complex piece of software – at some point – you need to find a way to manage its logical parts and dependencies between them. In fact, we considered this to be so important that we dedicated a whole (open-source) Rust crate to the elegant management of logical dependencies: Daab.

First of all, we need to understand the implications of a dependency between two components. If component A depends on component B, component A needs to be updated when changes to B are made. To account for updating components in such a case, Daab differentiates between two layers: The Builder layer and the Artifact layer.

Dependencies are usually expressed in a so-called Directed Acyclic Graph, or DAG in short. Daab is no exception to this. It also uses a DAG to represent logical dependencies between logical components.

Leave a Reply