-
Notifications
You must be signed in to change notification settings - Fork 196
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
Implement lazy loading mechanism for expensive metadata providers #720
Conversation
Nice! Looks like there are some test failures, most of them in |
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.
Let's fix test failures and add some new unit tests that exercise the new functionality directly. There are some type checker failures too, there are instructions in the readme about how you can set this up on your local machine without relying on CI.
libcst/_metadata_dependent.py
Outdated
:func:`~libcst.MetadataDependent.get_metadata`. | ||
""" | ||
|
||
def __init__(self, callable: Callable) -> None: |
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.
This will need to be a bit more strictly typed. LazyValue
will need to be generic over some T
value, and this callable will be typed as Callable[[], T]
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.
I have addressed the comments in the new commits. Thanks!
Codecov Report
@@ Coverage Diff @@
## main #720 +/- ##
=======================================
Coverage 94.80% 94.81%
=======================================
Files 247 247
Lines 25731 25762 +31
=======================================
+ Hits 24395 24425 +30
- Misses 1336 1337 +1
Continue to review full report at Codecov.
|
libcst/metadata/name_provider.py
Outdated
|
||
class QualifiedNameProvider(BatchableMetadataProvider[Collection[QualifiedName]]): | ||
|
||
class QualifiedNameProvider(BatchableMetadataProvider[_UNDEFINED_DEFAULT]): |
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.
Looks great overall, we just gotta figure out this type here. I'll look at it tomorrow a bit more closely
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.
Sure, thanks a lot!
I've fixed the typing issues and added LazyValue support to the base metadata provider in my latest commit. We still need:
|
The tests |
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.
Nice!
0.4.7 - 2022-07-12 Fixed * Fix get_qualified_names_for matching on prefixes of the given name by @lpetre in Instagram/LibCST#719 Added * Implement lazy loading mechanism for expensive metadata providers by @Chenguang-Zhu in Instagram/LibCST#720 0.4.6 - 2022-07-04 New Contributors - @superbobry made their first contribution in Instagram/LibCST#702 Fixed - convert_type_comments now preserves comments following type comments by @superbobry in Instagram/LibCST#702 - QualifiedNameProvider optimizations - Cache the scope name prefix to prevent scope traversal in a tight loop by @lpetre in Instagram/LibCST#708 - Faster qualified name formatting by @lpetre in Instagram/LibCST#710 - Prevent unnecessary work in Scope.get_qualified_names_for_ by @lpetre in Instagram/LibCST#709 - Fix parsing of parenthesized empty tuples by @zsol in Instagram/LibCST#712 - Support whitespace after ParamSlash by @zsol in Instagram/LibCST#713 - [parser] bail on deeply nested expressions by @zsol in Instagram/LibCST#718 0.4.5 - 2022-06-17 New Contributors - @zzl0 made their first contribution in Instagram/LibCST#704 Fixed - Only skip supported escaped characters in f-strings by @zsol in Instagram/LibCST#700 - Escaping quote characters in raw string literals causes a tokenizer error by @zsol in Instagram/LibCST#668 - Corrected a code example in the documentation by @zzl0 in Instagram/LibCST#703 - Handle multiline strings that start with quotes by @zzl0 in Instagram/LibCST#704 - Fixed a performance regression in libcst.metadata.ScopeProvider by @lpetre in Instagram/LibCST#698 0.4.4 - 2022-06-13 New Contributors - @adamchainz made their first contribution in Instagram/LibCST#688 Added - Add package links to PyPI by @adamchainz in Instagram/LibCST#688 - native: add overall benchmark by @zsol in Instagram/LibCST#692 - Add support for PEP-646 by @zsol in Instagram/LibCST#696 Updated - parser: use references instead of smart pointers for Tokens by @zsol in Instagram/LibCST#691
Summary
LazyValue
class, which postpones the loading of some expensive metadata, e.g., qualified names, to the time of callingget_metadata
QualifiedNameProvider
to use this lazy loading mechanismTest Plan
With this lazy loading, the running time of the function
QualifiedNameVisitor.on_visit
is supposed to be reduced by 20% on average.