Performance refactor https://github.com/KanoComputing/peldins/issues/949

https://github.com/KanoComputing/peldins/issues/949