Add `alignment_base`
Opened this issue · 0 comments
Some nodes depend only on when knots occur, and not on their values.
For example, consider:
x = pulse(Hour(1))
y = align(1, x)
z = align(2, y)
w = align(2, x)
Because of the semantics of align
, we know that z
and w
are identical timeseries, but currently TimeDag
can't infer this.
We can add a class of optimisations by adding alignment_base(::Node) -> Node
, which takes a node, and returns the "oldest ancestor" node which is known to have knots exactly aligned with it.
A new implementation of align(x, y)
would then only depend on alignment_base(y)
, and not y
itself.
In general, it is valid for alignment_base(x) = x
as a fallback, but in some cases it's possible to do better — we just have to decide where on the node the alignment base is stored.
Option 1:
Add a Node.alignment_base::Maybe{Node}
field, which is set iff the node has an alignment base other than itself.
The only problem with this is increasing the size of all Node
objects, even when there isn't any more optimisation.
Option 2:
Add a level of abstraction, and only specify the new member on a new NodeWithAlignmentBase <: AbstractNode
.
This avoids extra memory usage, but might create other issues
NB: care should be taken that everything works nicely with the identity map!