Skip to content
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

Speed up exception handling by re-using Environments #7143

Merged
merged 7 commits into from
Dec 20, 2023

Conversation

jogo
Copy link
Contributor

@jogo jogo commented Dec 19, 2023

Address #7142

By taking advantage of the caching logic in Environment

@jogo
Copy link
Contributor Author

jogo commented Dec 19, 2023

test code from #7142 before:

Before: 1.58
After: 0.02

cProfile data confirms jinja2 call times drop significantly

Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jogo, thanks for the PR! Please see my comments

moto/cloudfront/exceptions.py Outdated Show resolved Hide resolved
moto/elasticache/exceptions.py Show resolved Hide resolved
moto/core/exceptions.py Outdated Show resolved Hide resolved
moto/elasticache/exceptions.py Show resolved Hide resolved
moto/core/exceptions.py Outdated Show resolved Hide resolved
@jogo jogo requested a review from bblommers December 19, 2023 17:23
if template in self.templates.keys():
env = Environment(loader=DictLoader(self.templates))
self.description: str = env.get_template(template).render(
if template in self.env.list_templates():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since templates isn't updated only self.env is (changed when adding extended_environment to make the code less repetitive

@bblommers bblommers linked an issue Dec 19, 2023 that may be closed by this pull request
Copy link

codecov bot commented Dec 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (34a0c20) 95.88% compared to head (97db050) 95.88%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7143   +/-   ##
=======================================
  Coverage   95.88%   95.88%           
=======================================
  Files         834      834           
  Lines       82249    82253    +4     
=======================================
+ Hits        78862    78868    +6     
+ Misses       3387     3385    -2     
Flag Coverage Δ
servertests 35.81% <100.00%> (+0.02%) ⬆️
unittests 95.82% <100.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jogo
Copy link
Contributor Author

jogo commented Dec 19, 2023

Unclear what the issue is with the two failing CI jobs:

Error: Failed to CreateArtifact: Received non-retryable error: Failed request: (409) Conflict: an artifact with this name already exists on the workflow run
https://github.com/getmoto/moto/actions/runs/7268541069/job/19804663130?pr=7143
https://github.com/getmoto/moto/actions/runs/7268541069/job/19804663439?pr=7143

@bblommers
Copy link
Collaborator

Unclear what the issue is with the two failing CI jobs:

That must be unrelated - I'll look at that later on.

LGTM - thank you again for the PR @jogo!

@bblommers bblommers added this to the 4.2.13 milestone Dec 20, 2023
@bblommers bblommers merged commit eccb2b0 into getmoto:master Dec 20, 2023
30 of 32 checks passed
@jogo jogo deleted the faster_exceptions branch December 20, 2023 00:57
@jogo
Copy link
Contributor Author

jogo commented Dec 20, 2023

Thank you @bblommers for the quick turnaround on this, much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow s3 exception raising due to usage pattern of jinja2
2 participants