-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(taps): Change SQLStream.schema
into a cached property
#1745
refactor(taps): Change SQLStream.schema
into a cached property
#1745
Conversation
Schema is called at least once per record and does not change within a stream, so it should be cached for performance benefits.
``` @Property @lru_cache() ``` is a backwards compatible version of functools.cached_property for Python 3.7 https://stackoverflow.com/questions/4037481/caching-class-attributes-in-python
for more information, see https://pre-commit.ci
SQLStream.schema
into a cached property
@mjsqu can you fix the failing mypy check? Some of the conversation in python/mypy#5107 (comment) might be helpful. Thanks! |
mypy checks fail because the schema return type is lru_cache: ``` singer_sdk/streams/sql.py:82: error: Signature of "schema" incompatible with supertype "Stream" [override] singer_sdk/streams/sql.py:154: error: Argument "schema" to "get_selected_schema" has incompatible type "_lru_cache_wrapper[Dict[Any, Any]]"; expected "Dict[Any, Any]" [arg-type] Found 2 errors in 1 file (checked 59 source files) ``` The update should pass over the `_lru_cache_wrapper` type and return a `Dict` as expected
for more information, see https://pre-commit.ci
- Remove `lru_cache` - Set `_cached_schema` up as a class variable to hold the schema for each stream - Check for presence of `self._cached_schema` on the stream
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Codecov Report
@@ Coverage Diff @@
## main #1745 +/- ##
=======================================
Coverage 85.47% 85.48%
=======================================
Files 59 59
Lines 4888 4891 +3
Branches 802 803 +1
=======================================
+ Hits 4178 4181 +3
Misses 510 510
Partials 200 200
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Thanks for the inspiration @qbatten Done a quick test in https://github.com/mjsqu/tap-db2/blob/feature/meltano_sdk/tap_db2/client.py - still getting the speed benefit |
SQLStream.schema
into a cached propertySQLStream.schema
into a cached property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mjsqu!
Schema is called at least once per record and does not change within a stream, so it should be cached for performance benefits.
https://app.slack.com/client/TFG99TU9K/C013Z450LCD/thread/C013Z450LCD-1685703921.187269
📚 Documentation preview 📚: https://meltano-sdk--1745.org.readthedocs.build/en/1745/