OpenCyphal / pydsdl

Cyphal DSDL processing front end implemented in Python
https://opencyphal.org
MIT License
11 stars 9 forks source link

Introduce TaggedUnionType to properly model DSDL unions. #34

Closed thirtytwobits closed 4 years ago

thirtytwobits commented 4 years ago

Fixes #34 by making TaggedUnion a struct containing a tag and union field.

coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 31560865


Totals Coverage Status
Change from base Build 297: 0%
Covered Lines:
Relevant Lines: 0

💛 - Coveralls
thirtytwobits commented 4 years ago

Okay. This is what that would look like (I think). The remaining work would be to:

  1. Fix the tests
  2. Adapt consumers to test for new Variant attribute type.
thirtytwobits commented 4 years ago

So, in this version I went ahead and made Union a serializable type but the problem is, it's not Serializable. This is why is seemed to work when it was an Attribute but now I'm not sure it can work at all.

pavel-kirienko commented 4 years ago

As a side note, may I suggest that we avoid force-pushing too much? Keeping more context around is helpful. If you feel strongly about redundant commits they can always be squashed later.

thirtytwobits commented 4 years ago

Also optimized some hotspots:

pytest --profile --profile-svg -k _unittest_composite_types

========================================================= test session starts =========================================================
platform darwin -- Python 3.7.5, pytest-4.6.9, py-1.8.1, pluggy-0.13.1 -- /Volumes/workspace/github32/pydsdl/.pyenv/bin/python3.7
cachedir: .pytest_cache
rootdir: /Volumes/workspace/github32/pydsdl, inifile: setup.cfg, testpaths: pydsdl
plugins: profiling-1.7.0
collected 45 items / 44 deselected / 1 selected

pydsdl/_serializable/_composite.py::_unittest_composite_types PASSED                                                            [100%]
Profiling (from /Volumes/workspace/github32/pydsdl/prof/combined.prof):
Mon Mar 16 21:37:49 2020    /Volumes/workspace/github32/pydsdl/prof/combined.prof

         428453710 function calls (426451421 primitive calls) in 152.342 seconds

   Ordered by: cumulative time
   List reduced from 567 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000  152.342  152.342 runner.py:76(pytest_runtest_protocol)
    15/11    0.000    0.000  152.342   13.849 hooks.py:272(__call__)
    15/11    0.000    0.000  152.341   13.849 manager.py:90(_hookexec)
    15/11    0.000    0.000  152.341   13.849 manager.py:84(<lambda>)
    15/11    0.000    0.000  152.341   13.849 callers.py:157(_multicall)
        1    0.000    0.000  152.340  152.340 runner.py:83(runtestprotocol)
        3    0.000    0.000  152.340   50.780 runner.py:172(call_and_report)
        3    0.000    0.000  152.339   50.780 runner.py:191(call_runtest_hook)
        3    0.000    0.000  152.339   50.780 runner.py:219(from_call)
        3    0.000    0.000  152.339   50.780 runner.py:198(<lambda>)
        1    0.000    0.000  152.338  152.338 runner.py:119(pytest_runtest_call)
        1    0.000    0.000  152.338  152.338 python.py:1462(runtest)
        1    0.000    0.000  152.338  152.338 python.py:160(pytest_pyfunc_call)
        1    0.192    0.192  152.338  152.338 _composite.py:455(_unittest_composite_types)
        4    1.665    0.416  143.077   35.769 _composite.py:573(try_union_fields)
  2002023    1.648    0.000  131.419    0.000 _attribute.py:22(__init__)
  2002075   23.899    0.000  127.594    0.000 _name.py:15(check_name)
 58060030   18.876    0.000  103.695    0.000 re.py:170(match)
 58060040   37.651    0.000   67.070    0.000 re.py:271(_compile)
 58060030   15.243    0.000   25.613    0.000 types.py:164(__get__)

with this change:

========================================================= test session starts =========================================================
platform darwin -- Python 3.7.5, pytest-4.6.9, py-1.8.1, pluggy-0.13.1 -- /Volumes/workspace/github32/pydsdl/.pyenv/bin/python3.7
cachedir: .pytest_cache
rootdir: /Volumes/workspace/github32/pydsdl, inifile: setup.cfg, testpaths: pydsdl
plugins: profiling-1.7.0
collected 45 items / 44 deselected / 1 selected

pydsdl/_serializable/_composite.py::_unittest_composite_types PASSED                                                            [100%]
Profiling (from /Volumes/workspace/github32/pydsdl/prof/combined.prof):
Mon Mar 16 21:23:41 2020    /Volumes/workspace/github32/pydsdl/prof/combined.prof

         156169533 function calls (154167287 primitive calls) in 43.597 seconds

   Ordered by: cumulative time
   List reduced from 564 to 20 due to restriction <20>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   43.597   43.597 runner.py:76(pytest_runtest_protocol)
    15/11    0.000    0.000   43.597    3.963 hooks.py:272(__call__)
    15/11    0.000    0.000   43.597    3.963 manager.py:90(_hookexec)
    15/11    0.000    0.000   43.597    3.963 manager.py:84(<lambda>)
    15/11    0.000    0.000   43.597    3.963 callers.py:157(_multicall)
        1    0.000    0.000   43.595   43.595 runner.py:83(runtestprotocol)
        3    0.000    0.000   43.595   14.532 runner.py:172(call_and_report)
        3    0.000    0.000   43.594   14.531 runner.py:191(call_runtest_hook)
        3    0.000    0.000   43.594   14.531 runner.py:219(from_call)
        3    0.000    0.000   43.594   14.531 runner.py:198(<lambda>)
        1    0.000    0.000   43.593   43.593 runner.py:119(pytest_runtest_call)
        1    0.000    0.000   43.593   43.593 python.py:1462(runtest)
        1    0.000    0.000   43.593   43.593 python.py:160(pytest_pyfunc_call)
        1    0.192    0.192   43.593   43.593 _composite.py:514(_unittest_composite_types)
        4    1.470    0.367   34.124    8.531 _composite.py:632(try_union_fields)
  2002033    1.400    0.000   22.572    0.000 _attribute.py:22(__init__)
  2002103   12.016    0.000   19.544    0.000 _name.py:16(check_name)
        7    0.385    0.055    9.915    1.416 _composite.py:382(__init__)
 82085945    6.993    0.000    9.652    0.000 {built-in method builtins.isinstance}
2002032/12    0.627    0.000    9.274    0.773 _serializable.py:31(bit_length_set)