GNOME Bugzilla – Bug 723872
Fast path Python defined property access
Last modified: 2014-08-18 09:17:27 UTC
Accessing GObject properties defined in Python go through a large amount of machinery to marshal a Python value to a C GValue only to be marshaled back to a Python value. This could be fast-pathed so accessing a Python defined property simply returns the results of the Python defined getter. For example: #### from gi.repository import GObject class Spam(GObject.Object): eggs = GObject.Property(type=int) spam = Spam() print(spam.eggs) #### The above code will do an enormous amount of work to retrieve a simple integer already stored in a Python dictionary. Fast-pathing property accesses which use the form "spam.eggs" should be fairly trivial, but an attempt should also be made to look to look at other accessor forms like "spam.get_property('eggs')" and "spam.props.eggs". An additional caveat is we need to catch all exceptions and print them before returning within the fast path accessor to maintain current behaviour (bug 616279).
Created attachment 282970 [details] [review] tests: Add failing tests which verify exceptions raised in property getters https://bugzilla.gnome.org/show_bug.cgi?id=575652 https://bugzilla.gnome.org/show_bug.cgi?id=726999
Created attachment 282971 [details] [review] Fast path Python Property getter when accessing descriptor directly Call the Python implemented fget() when a property is accessed directly on a Python implemented GObject. This skips going through the GObject machinery which ends up calling fget() and marshalling the results through GValues.
Created attachment 282972 [details] [review] Fast path Python Property getter when accessed through GObject interfaces Break do_get_property() call into a re-usable function. Call do_get_property() Python implementations instead of going through GObject machinery for Python GObjects. This gives a performance boost for Python GObject properties when accessed via. obj.get_property() and obj.props.
The patches are dependent on patches in bug 726999. Some micro benchmarks: # Before patches: %timeit spam.eggs 100000 loops, best of 3: 6.69 us per loop %timeit spam.props.eggs 100000 loops, best of 3: 6.61 us per loop %timeit spam.get_property('eggs') 100000 loops, best of 3: 5.87 us per loop # After patches: %timeit spam.eggs 1000000 loops, best of 3: 1.47 us per loop %timeit spam.props.eggs 100000 loops, best of 3: 4.66 us per loop %timeit spam.get_property('eggs') 100000 loops, best of 3: 4.19 us per loop
Comment on attachment 282970 [details] [review] tests: Add failing tests which verify exceptions raised in property getters Committed tests as: https://git.gnome.org/browse/pygobject/commit/?id=b1caef9
Attachment 282971 [details] pushed as 0a99f87 - Fast path Python Property getter when accessing descriptor directly Attachment 282972 [details] pushed as 5b82051 - Fast path Python Property getter when accessed through GObject interfaces