Optimize away some unnecessary repeated calls and add a bit of debug logging

--HG--
extra : histedit_source : 9973ffcee8bedd2e9db2bf3f9fd7d865b7882838
This is probably better as private...

--HG--
extra : histedit_source : d59d360f9ba4e9bf07f071641e1ffaaa238d83ed