-
Notifications
You must be signed in to change notification settings - Fork 429
Feature request: Improve cold start by optimizing imports in Powertools utilities #5820
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
Comments
Hey @ran-isenberg! Thanks for bringing up this question. I understand you concerns here and adoption best practices, but I'm unsure if this impact coldstart because we are import Python top level importsThe way Python works, it doesn't matter if you import from Making names more explicitIn this particular file, we're using boto3's Performance test when importing boto3I did a local performance test by importing only This is the result of using the current code: And this is the result of using Note that in the images the imports are exactly the same, which means that it makes no difference whether we What causes an impact in this case is when we create the boto3 instance to make calls to Please let me know if you have any other findings or tests that I can use to better understand the impact of this. I would be more than happy to reduce any impact caused by Powertools's imports. |
Thank you for the amazing response @leandrodamascena ! That's a bummer, because in other languages it does make a difference, like in this video (I put the exact time): |
I'm not saying that. What I'm saying is that importing the entire
Yep, the result will be the same.
Even in Python, this makes a difference in some cases. For example, in Powertools, if you import just This flexibility of Python allows you to optimize some areas, have more specific imports for modules and things like that. |
fixed the link https://www.youtube.com/watch?v=IHFJ-0_3cXY&t=2244s |
Oh yeah, I watched that video, thanks for sharing. For example, Pydantic v2 had a significant performance regression when importing things because they were loading unnecessary stuff. I reported some data in this thread: pydantic/pydantic#6748 (comment). They have changed a lot of things and are now more fast. I believe this can happen in all languages, but since we are running the code inside AWS Lambda, where every ms counts and we have limited resources, we have more attention to these details.
Done |
I'm closing this issue! Please feel free to reopen @ran-isenberg |
|
Use case
Hey,
In order to improve cold start, we are often told not to import an entire library (especially if it's large) such as 'import X' but instead import specific classes, like: 'from X import Y'.
I've noticed that some utilities dont follows this best practice:
for example
powertools-lambda-python/aws_lambda_powertools/utilities/parameters/appconfig.py
Line 11 in e29e290
Solution/User Experience
For example: change 'import boto3' to 'from boto3 import client'
Alternative solutions
Acknowledgment
The text was updated successfully, but these errors were encountered: