GNOME Bugzilla – Bug 723736
Add API for enabling features and fixes which break compatibililty
Last modified: 2018-01-10 20:37:24 UTC
The idea is to provide an API which allows for turning on (or off) features in PyGObject that would break API compatibility. Similar to Python's "from __future__ import X" statement. It looks like there are some dead remnants of a similar API from PyGObject 2: https://git.gnome.org/browse/pygobject/tree/gi/gobjectmodule.c?id=3.11.5#n2157 This uses a dictionary which offers a fairly clean API: gi.features['X'] = True gi.features['X'] = False gi.features['X'] We just need to button it up a bit and expose it as "gi.features" which is filled out with False defaults. Some initial features which could make use of this: * Deprecate initialize overrides (bug 705810). Since we can't actually remove the deprecated functions, it would be nice to explicitly disable the loading of them. By putting the overrides behind a logic test for classes which have these, we can improve load time performance for programs that need this speedup (Sugar OS). gi.features['skip_initializer_overrides'] * Skipping array/list length arguments for callbacks (bug 652115). We currently pass the length argument explicitly to callbacks. Changing this is an API break. gi.features['skip_redundant_callback_args'] * Zero copy support of arrays (bug 709976). Some API's which return GArrays coerced to Python lists would return a direct wrapper to the GArray. While the API could be made the same as a Python list, this might break some expectations callers have so it would need explicit enablement. gi.features['zero_copy_arrays'] * Propagate exceptions from callbacks (bug 616279). Fixing this would break caller expectations so would require explicit enablement. gi.features['propagate_callback_exceptions']
Created attachment 272464 [details] [review] Add load time option to remove deprecated initializers Add gi.options dictionary to the main gi module. This gives a new table for optional behavior in overrides and binding machinery which may break things in a backwards incompatible way. Add "remove_deprecated_initializers" option used in Gtk overrides for blocking the loading of class overrides that only contain deprecated initializers. When enabled, we get about a 12% performance boost when importing Gtk. This can be enabled as follows: import gi gi.options['remove_deprecated_initializers'] = True from gi.repository import Gtk
Created attachment 272465 [details] [review] Patch with the new table called "options" instead of "features".
Performance was tested as follows: $ python3 -m timeit -n 1 -r 1 --setup "import gi; gi.options['remove_deprecated_initializers'] = False" "from gi.repository import Gtk" 1 loops, best of 1: 53.6 msec per loop $ python3 -m timeit -n 1 -r 1 --setup "import gi; gi.options['remove_deprecated_initializers'] = True" "from gi.repository import Gtk" 1 loops, best of 1: 46.5 msec per loop These are the best of about 10 runs each. While a performance improvement of 8 msec (13%) is not very much on my super computer :) This will most likely be a lot more significant on something like a raspberry pi or xo laptop.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/65.