About commit 848239d, it's not the isinstance call per se that was slow, but the use of the Number ABC.
I suggest getting rid of the Number ABC and replacing it by:
Number = int if _version3 else (int, long)
and use isinstance on that in color, bk_color, put and put_ext.
(Sorry I don't have mercurial installed to submit pull requests).
edit: long support in python 2 is important at least for color and bk_color