robotools / vanilla

A Pythonic wrapper around Cocoa.
MIT License
78 stars 28 forks source link

All window bindings call hasattr. #178

Closed typesupply closed 1 year ago

typesupply commented 1 year ago

All window bindings (most significantly resize and move) call the _alertBindings method. This method makes extensive use of hasattr and Window is a subclass of NSObject. In the past, hasattr has been a major performance issue for PyObjC when used in code that is called frequently. During move and resize, this will be called very frequently.

We should figure out a way to eliminate the hasattr use. The _alertBindings method has notes about why hasattr is used, but looking at it many years later, I wonder if the solution may be to simply establish the bindings dict before the window delegate is set.

typemytype commented 1 year ago

moving the _binding dict to class level should also enable that the attribute is always available