After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 723872 - Fast path Python defined property access
Fast path Python defined property access
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 726999
Blocks: 575652
 
 
Reported: 2014-02-07 20:54 UTC by Simon Feltman
Modified: 2014-08-18 09:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
tests: Add failing tests which verify exceptions raised in property getters (1.51 KB, patch)
2014-08-09 09:42 UTC, Simon Feltman
none Details | Review
Fast path Python Property getter when accessing descriptor directly (2.10 KB, patch)
2014-08-09 09:43 UTC, Simon Feltman
committed Details | Review
Fast path Python Property getter when accessed through GObject interfaces (4.48 KB, patch)
2014-08-09 09:43 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2014-02-07 20:54:36 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).
Comment 1 Simon Feltman 2014-08-09 09:42:25 UTC
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
Comment 2 Simon Feltman 2014-08-09 09:43:02 UTC
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.
Comment 3 Simon Feltman 2014-08-09 09:43:25 UTC
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.
Comment 4 Simon Feltman 2014-08-09 09:44:33 UTC
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 5 Simon Feltman 2014-08-09 20:15:04 UTC
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
Comment 6 Simon Feltman 2014-08-18 09:17:19 UTC
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