seandstewart / typical

Typical: Fast, simple, & correct data-validation using Python 3 typing.
https://python-typical.org
MIT License
183 stars 9 forks source link

Optimize signature binding and other fixups #175

Closed seandstewart closed 2 years ago

seandstewart commented 2 years ago

Optimizations

This change introduces an overhauled evaluation of callable signatures which now provides comparable performance to our serdes protocol bindings.


import dataclasses
import timeit
import typic

@dataclasses.dataclass
class Foo:
    bar: str

@dataclasses.dataclass(frozen=True)
class Froze:
    bar: str

foo_proto = typic.protocol(Foo)
froze_proto = typic.protocol(Froze)

print(timeit.timeit('foo_proto.transmute({"bar": 1})', globals=globals()))
#> 2.1221675970000007
print(timeit.timeit('froze_proto.transmute({"bar": 1})', globals=globals()))
#> 2.264840293000006

The previous implementation was up to 10X slower.

Improvements

More descriptive type-hints for our api module to aid IDE and MyPy.

Fixes

Resolves the issues mentioned in #170 & #174

codecov[bot] commented 2 years ago

Codecov Report

Merging #175 (bd0334f) into main (0f1fc60) will increase coverage by 0.13%. The diff coverage is 98.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
+ Coverage   94.84%   94.98%   +0.13%     
==========================================
  Files          37       37              
  Lines        4058     4125      +67     
  Branches      558      575      +17     
==========================================
+ Hits         3849     3918      +69     
+ Misses        130      128       -2     
  Partials       79       79              
Flag Coverage Δ
unittests 94.86% <98.52%> (+0.13%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
typic/constraints/factory.py 98.19% <ø> (ø)
typic/serde/translator.py 98.78% <ø> (-0.02%) :arrow_down:
typic/api.py 95.69% <95.45%> (-0.95%) :arrow_down:
typic/serde/des.py 92.91% <96.15%> (+0.47%) :arrow_up:
typic/__init__.py 100.00% <100.00%> (ø)
typic/checks.py 97.33% <100.00%> (+0.09%) :arrow_up:
typic/compat.py 100.00% <100.00%> (ø)
typic/ext/schema/schema.py 98.91% <100.00%> (ø)
typic/serde/binder.py 100.00% <100.00%> (ø)
typic/serde/resolver.py 94.13% <100.00%> (+0.43%) :arrow_up:
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 125b3bd...bd0334f. Read the comment docs.