Skip to content

`@with_signature`: avoid tuple limit by using `get_variable` unpacking directly in function body

Florian Atteneder requested to merge fa/fix-alloc-with-sig into main

The implementation of the doublecartoon formulation in GRHD finally hit the tuple length limit, above which tuples are stack allocated and, thus, incur a drastic performance hit due to extra allocs.

Here we update @with_signature so that we no longer have to pass arguments through tuples, but instead we look them up with the get_variable method from mesh.cache. This way we also do the unpacking now directly inside the macro-generated function body.

Its not an ideal solution, because now @with_signature can no longer be used without the get_variable method from dg1d, which increases coupling. But for the moment I don't bother, and I shall worry about that whenever I decided to move @with_signature into a separate pkg, if ever.


The get_variable method and Cache could also use a bit of benchmarking and optimizations. E.g. atm we perform three lookups

  • isregistered to check if the variable is available
  • Cache.variables_to_fields to determine in which variable group the variable can be found
  • getproperty(::Variable, ::Symbol) to get the variable

Clearly, this could be improved, but we leave that for the future.


Obviously, I also updated the tests. But I refused to setup now Caches for each test case. Instead I just added a dispatch get_variable(::NamedTuple, ::Symbol) and a cache argument to the expanded function so that the tests didn't so much adjustments.

Merge request reports