Disclaimer, what follows is either pretty neat, or pure-evil depending your your viewpoint ;) But it's based on a real use-case and it works, so I'm posting this to document the approach, why it's needed, and hopefully stimulate some discussion around optimizations leading to a improved/simplified implementation in the future.