1. 22 Apr, 2017 7 commits
    • Damien George's avatar
      py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls. · dd11af20
      Damien George authored
      This patch allows the following code to run without allocating on the heap:
      
          super().foo(...)
      
      Before this patch such a call would allocate a super object on the heap and
      then load the foo method and call it right away.  The super object is only
      needed to perform the lookup of the method and not needed after that.  This
      patch makes an optimisation to allocate the super object on the C stack and
      discard it right after use.
      
      Changes in code size due to this patch are:
      
         bare-arm: +128
          minimal: +232
         unix x64: +416
      unix nanbox: +364
           stmhal: +184
          esp8266: +340
           cc3200: +128
      dd11af20
    • Damien George's avatar
      py/compile: Refactor handling of special super() call. · 5335942b
      Damien George authored
      This patch refactors the handling of the special super() call within the
      compiler.  It removes the need for a global (to the compiler) state variable
      which keeps track of whether the subject of an expression is super.  The
      handling of super() is now done entirely within one function, which makes
      the compiler a bit cleaner and allows to easily add more optimisations to
      super calls.
      
      Changes to the code size are:
      
         bare-arm: +12
          minimal:  +0
         unix x64: +48
      unix nanbox: -16
           stmhal:  +4
           cc3200:  +0
          esp8266: -56
      5335942b
    • Damien George's avatar
      py/compile: Don't do unnecessary check if iter parse node is a struct. · 0dd6a59c
      Damien George authored
      If we get to this point in the code then pn_iter is guaranteed to be a
      struct.
      0dd6a59c
    • Damien George's avatar
      py/compile: Add COMP_RETURN_IF_EXPR option to enable return-if-else opt. · ae54fbf1
      Damien George authored
      With this optimisation enabled the compiler optimises the if-else
      expression within a return statement.  The optimisation reduces bytecode
      size by 2 bytes for each use of such a return-if-else statement.  Since
      such a statement is not often used, and costs bytes for the code, the
      feature is disabled by default.
      
      For example the following code:
      
          def f(x):
              return 1 if x else 2
      
      compiles to this bytecode with the optimisation disabled (left column is
      bytecode offset in bytes):
      
          00 LOAD_FAST 0
          01 POP_JUMP_IF_FALSE 8
          04 LOAD_CONST_SMALL_INT 1
          05 JUMP 9
          08 LOAD_CONST_SMALL_INT 2
          09 RETURN_VALUE
      
      and to this bytecode with the optimisation enabled:
      
          00 LOAD_FAST 0
          01 POP_JUMP_IF_FALSE 6
          04 LOAD_CONST_SMALL_INT 1
          05 RETURN_VALUE
          06 LOAD_CONST_SMALL_INT 2
          07 RETURN_VALUE
      
      So the JUMP to RETURN_VALUE is optimised and replaced by RETURN_VALUE,
      saving 2 bytes and making the code a bit faster.
      ae54fbf1
    • Damien George's avatar
      py/compile: Extract parse-node kind at start of func for efficiency. · 40b40ffc
      Damien George authored
      Otherwise the type of parse-node and its kind has to be re-extracted
      multiple times.  This optimisation reduces code size by a bit (16 bytes on
      bare-arm).
      40b40ffc
    • Damien George's avatar
      py/compile: Don't do unnecessary check if parse node is a struct. · fa03bbf0
      Damien George authored
      PN_atom_expr_normal parse nodes always have structs for their second
      sub-node, so simplify the check for the sub-node kind to save code size.
      fa03bbf0
    • Damien George's avatar
      py/objtype: mp_obj_new_super doesn't need to be public, so inline it. · 4df013c8
      Damien George authored
      Saves code size (20 bytes on bare-arm) and makes it a tiny bit more
      efficient.
      4df013c8
  2. 21 Apr, 2017 2 commits
  3. 18 Apr, 2017 1 commit
  4. 12 Apr, 2017 5 commits
    • Damien George's avatar
      py/gc: Execute finaliser code in a protected environment. · c7e8c6f7
      Damien George authored
      If a finaliser raises an exception then it must not propagate through the
      GC sweep function.  This patch protects against such a thing by running
      finaliser code via the mp_call_function_1_protected call.
      
      This patch also adds scheduler lock/unlock calls around the finaliser
      execution to further protect against any possible reentrancy issues: the
      memory manager is already locked when doing a collection, but we also don't
      want to allow any scheduled code to run, KeyboardInterrupts to interupt the
      code, nor threads to switch.
      c7e8c6f7
    • Damien George's avatar
      py/nlrsetjmp: Add check for failed NLR jump. · 08242eed
      Damien George authored
      Also optimise the function so it only needs to call the MP_STATE_THREAD
      macro once (following how other nlr code is written).
      08242eed
    • Damien George's avatar
      py/objfloat: Add implementation of high-quality float hashing. · a73501b1
      Damien George authored
      Disabled by default.
      a73501b1
    • Damien George's avatar
      py: Optimise types for common case where type has a single parent type. · 816413e4
      Damien George authored
      The common cases for inheritance are 0 or 1 parent types, for both built-in
      types (eg built-in exceptions) as well as user defined types.  So it makes
      sense to optimise the case of 1 parent type by storing just the type and
      not a tuple of 1 value (that value being the single parent type).
      
      This patch makes such an optimisation.  Even though there is a bit more
      code to handle the two cases (either a single type or a tuple with 2 or
      more values) it helps reduce overall code size because it eliminates the
      need to create a static tuple to hold single parents (eg for the built-in
      exceptions).  It also helps reduce RAM usage for user defined types that
      only derive from a single parent.
      
      Changes in code size (in bytes) due to this patch:
      
          bare-arm:       -16
          minimal (x86): -176
          unix (x86-64): -320
          unix nanbox:   -384
          stmhal:         -64
          cc3200:         -32
          esp8266:       -108
      816413e4
    • Damien George's avatar
  5. 11 Apr, 2017 2 commits
  6. 10 Apr, 2017 2 commits
  7. 05 Apr, 2017 2 commits
  8. 04 Apr, 2017 2 commits
  9. 02 Apr, 2017 2 commits
  10. 01 Apr, 2017 1 commit
  11. 31 Mar, 2017 1 commit
  12. 30 Mar, 2017 1 commit
  13. 29 Mar, 2017 6 commits
  14. 28 Mar, 2017 2 commits
    • Damien George's avatar
      py/lexer: Simplify and reduce code size for operator tokenising. · 5010d195
      Damien George authored
      By removing the 'E' code from the operator token encoding mini-language the
      tokenising can be simplified.  The 'E' code was only used for the !=
      operator which is now handled as a special case; the optimisations for the
      general case more than make up for the addition of this single, special
      case.  Furthermore, the . and ... operators can be handled in the same way
      as != which reduces the code size a little further.
      
      This simplification also removes a "goto".
      
      Changes in code size for this patch are (measured in bytes):
      
      bare-arm:       -48
      minimal x86:    -64
      unix x86-64:   -112
      unix nanbox:    -64
      stmhal:         -48
      cc3200:         -48
      esp8266:        -76
      5010d195
    • Damien George's avatar
      py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible. · 94c41bb0
      Damien George authored
      Saves 168 bytes on bare-arm.
      94c41bb0
  15. 27 Mar, 2017 2 commits
  16. 26 Mar, 2017 2 commits