<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/tests/misc/non_compliant.py.exp, branch master</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=master</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2018-06-08T02:12:08+00:00</updated>
<entry>
<title>py/objtype: Optimise instance get/set/del by skipping special accessors.</title>
<updated>2018-06-08T02:12:08+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2018-05-25T07:09:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=36c105218321167d47b0fb67575a7cddc36d17e7'/>
<id>urn:sha1:36c105218321167d47b0fb67575a7cddc36d17e7</id>
<content type='text'>
This patch is a code optimisation, trading text bytes for speed.  On
pyboard it's an increase of 0.06% in code size for a gain (in pystone
performance) of roughly 6.5%.

The patch optimises load/store/delete of attributes in user defined classes
by not looking up special accessors (@property, __get__, __delete__,
__set__, __setattr__ and __getattr_) if they are guaranteed not to exist in
the class.

Currently, if you do my_obj.foo() then the runtime has to do a few checks
to see if foo is a property or has __get__, and if so delegate the call.
And for stores things like my_obj.foo = 1 has to first check if foo is a
property or has __set__ defined on it.

Doing all those checks each and every time the attribute is accessed has a
performance penalty.  This patch eliminates all those checks for cases when
it's guaranteed that the checks will always fail, ie no attributes are
properties nor have any special accessor methods defined on them.

To make this guarantee it checks all attributes of a user-defined class
when it is first created.  If any of the attributes of the user class are
properties or have special accessors, or any of the base classes of the
user class have them, then it sets a flag in the class to indicate that
special accessors must be checked for.  Then in the load/store/delete code
it checks this flag to see if it can take the shortcut and optimise the
lookup.

It's an optimisation that's pretty widely applicable because it improves
lookup performance for all methods of user defined classes, and stores of
attributes, at least for those that don't have special accessors.  And, it
allows to enable descriptors with minimal additional runtime overhead if
they are not used for a particular user class.

There is one restriction on dynamic class creation that has been introduced
by this patch: a user-defined class cannot go from zero special accessors
to one special accessor (or more) after that class has been subclassed.  If
the script attempts this an AttributeError is raised (see addition to
tests/misc/non_compliant.py for an example of this case).

The cost in code space bytes for the optimisation in this patch is:

   unix x64:  +528
unix nanbox:  +508
      stm32:  +192
     cc3200:  +200
    esp8266:  +332
      esp32:  +244

Performance tests that were done:

- on unix x86-64, pystone improved by about 5%
- on pyboard, pystone improved by about 6.5%, from 1683 up to 1794
- on pyboard, bm_chaos (from CPython benchmark suite) improved by about 5%
- on esp32, pystone improved by about 30% (but there are caching effects)
- on esp32, bm_chaos improved by about 11%
</content>
</entry>
<entry>
<title>tests: Add tests to improve coverage of py/objtype.c.</title>
<updated>2017-12-14T01:25:30+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-14T01:25:30+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=36f79523abe8d79fec1cc7af41e8e96e8ceb2cc4'/>
<id>urn:sha1:36f79523abe8d79fec1cc7af41e8e96e8ceb2cc4</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/objset: Check that RHS of a binary op is a set/frozenset.</title>
<updated>2017-10-03T06:56:27+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-10-03T06:56:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=2ac1364688cd3ee313661e82a336663551986fc8'/>
<id>urn:sha1:2ac1364688cd3ee313661e82a336663551986fc8</id>
<content type='text'>
CPython docs explicitly state that the RHS of a set/frozenset binary op
must be a set to prevent user errors.  It also preserves commutativity of
the ops, eg: "abc" &amp; set() is a TypeError, and so should be set() &amp; "abc".

This change actually decreases unix (x64) code by 160 bytes; it increases
stm32 by 4 bytes and esp8266 by 28 bytes (but previous patch already
introduced a much large saving).
</content>
</entry>
<entry>
<title>tests/misc/non_compliant: Add test for inability to assign func attrs.</title>
<updated>2017-01-19T12:38:53+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-01-19T12:38:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=7314ebae8a3c7fae2c61427d428593ce84b4ccb5'/>
<id>urn:sha1:7314ebae8a3c7fae2c61427d428593ce84b4ccb5</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests: Add tests to improve coverage of objarray.c.</title>
<updated>2016-12-21T07:21:41+00:00</updated>
<author>
<name>Rami Ali</name>
<email>flowergrass@users.noreply.github.com</email>
</author>
<published>2016-12-21T06:51:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=1731868ae7a2d22e26e9ed939be18929fed81400'/>
<id>urn:sha1:1731868ae7a2d22e26e9ed939be18929fed81400</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests: Improve coverage of array, range, dict, slice, exc, unicode.</title>
<updated>2016-10-17T00:43:47+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-10-17T00:43:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=e9404e5f5f058db954ac0a92cb5acfcef6f6724a'/>
<id>urn:sha1:e9404e5f5f058db954ac0a92cb5acfcef6f6724a</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests: Improve test coverage of py/compile.c.</title>
<updated>2016-10-11T01:30:32+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-10-11T01:30:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=5e22afce41de8c87071d8fc149a6ba3cd8762819'/>
<id>urn:sha1:5e22afce41de8c87071d8fc149a6ba3cd8762819</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests: Improve coverage of struct with test for non-compliant behaviour.</title>
<updated>2016-10-07T01:57:25+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-10-07T01:57:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=82af4d6749072d01195da647f54b79c80f1ad731'/>
<id>urn:sha1:82af4d6749072d01195da647f54b79c80f1ad731</id>
<content type='text'>
</content>
</entry>
<entry>
<title>tests/misc/non_compliant: Add tests to improve coverage testing.</title>
<updated>2016-08-15T00:46:46+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2016-08-15T00:46:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=b359cf2911781120f5c866107734269435c4e424'/>
<id>urn:sha1:b359cf2911781120f5c866107734269435c4e424</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/mpz: Complete implementation of mpz_{and,or,xor} for negative args.</title>
<updated>2016-02-03T22:13:39+00:00</updated>
<author>
<name>Doug Currie</name>
<email>github.9.eeeeeee@spamgourmet.com</email>
</author>
<published>2016-01-31T03:35:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=2e2e15cec2f85ece763f3f80152d759aecfad47c'/>
<id>urn:sha1:2e2e15cec2f85ece763f3f80152d759aecfad47c</id>
<content type='text'>
For these 3 bitwise operations there are now fast functions for
positive-only arguments, and general functions for arbitrary sign
arguments (the fast functions are the existing implementation).

By default the fast functions are not used (to save space) and instead
the general functions are used for all operations.

Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive
arguments.
</content>
</entry>
</feed>
