first try at some profile-guided optimizations

in particular: in inner loops prefer type to isinstance, prefer locals