-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix generics creation time and allow model name reusing #2078
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
Fix generics creation time and allow model name reusing #2078
Conversation
combine get_caller_module_name and is_call_from_module in get_caller_frame_info
Codecov Report
@@ Coverage Diff @@
## master #2078 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 4094 4091 -3
Branches 821 822 +1
=========================================
- Hits 4094 4091 -3
Continue to review full report at Codecov.
|
| f'Name conflict: {model_name!r} in {model_module!r} is already used by {object_in_module!r}' | ||
| ) | ||
| if called_globally: # create global reference and therefore allow pickling | ||
| object_by_reference = 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.
Thanks for also taking care of this issue too besides performance one! 🎉
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 probably needs to be added in v1.7.2 once last tests to keep coverage at 100% are added and @samuelcolvin approves
|
Coverage should be fixed now Here's a benchmark showcasing the difference in speed between 1.7.1, 1.6.x and current PR: @bogdandm, could you run this one in your environment as well? |
|
Just decided to compare speed of calling import sys
from timeit import timeit
def get_caller_frame_info_new():
previous_caller_frame = sys._getframe(2)
frame_globals = previous_caller_frame.f_globals
return frame_globals.get('__name__'), previous_caller_frame.f_locals is frame_globals
def get_caller_frame_info_old():
# code of two functions placed in one and results are combined
import inspect
previous_caller_frame = inspect.stack()[2].frame
previous_caller_module = inspect.getmodule(previous_caller_frame, previous_caller_frame.f_code.co_filename)
name = previous_caller_module.__name__ if previous_caller_module is not None else None
import inspect
previous_caller_frame = inspect.stack()[2].frame
called_globally = previous_caller_frame.f_locals is previous_caller_frame.f_globals
return name, called_globally
def check():
assert get_caller_frame_info_new() == get_caller_frame_info_old()
check()
old = timeit(get_caller_frame_info_old, number=1000)
new = timeit(get_caller_frame_info_new, number=1000)
print('new: ', new)
print('old: ', old)
print('old / new: ', old / new)I'm getting this results new: 0.00040132100000001003
old: 1.176067545
old / new: 2930.490916249014Three. Thousand. Times. Faster. ON SSD. 🙈 I don't know what to say. Previous implementation is the definition of something unreasonably slow... |
|
This is looking great, I'm going to play with it myself but it looks good. Would also be good to wait for confirmation from @bogdandm. |
|
Once this is merged, I'll release v1.7.2. If there's anything else we should include, let me know. |
|
@MrMrRobat Could confirm that it is working (similar HDD setup, but a little bit faster disk I think) And 2000 times faster on SSD as well. |
|
Awesome. I'll make a new release in the morning. |
Change Summary
Creation time:
sys._getframe()instead of slowinspect.stack()frame.f_globalsinstead of slowinspect.getmodule()to retrieve caller module nameget_caller_module_name()withis_call_from_module()into more than 2000x 🙈 fasterget_caller_frame_info()Concrete names reusing:
'_'to global reference name if it's already in use instead of raisingTypeErrorRelated issue number
fix #2070
fix #2069
(updated: added "fix" so I don't forget to close both issues, @samuelcolvin)
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)