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

Skip caching calls (Resolves #667) #668

Merged
merged 2 commits into from
Sep 19, 2022
Merged

Skip caching calls (Resolves #667) #668

merged 2 commits into from
Sep 19, 2022

Conversation

vallentin
Copy link
Collaborator

@vallentin vallentin commented Apr 19, 2022

This is just a quick fix to address #667, and open up discussion.

Should we take any assumptions about interior mutability, statics and side-effects? i.e. never cache calls. Someone could potentially even make a "funky" impl Deref, making caching field accesses "wrong".

Alternative suggestion, we could introduce a config to disable caching.

(I'll add tests, update docs, etc. when I know whether we want a config or just take no assumptions and not cache)


New behavior:

{{ foo() }} {{ foo() }} {{ bar }}  {{ bar }}

Now generates:

::std::write!(
    writer,
    "{expr0} {expr1} {expr2}  {expr2}",
    expr0 = &::askama::MarkupDisplay::new_unsafe(&(self.foo()), ::askama::Text),
    expr1 = &::askama::MarkupDisplay::new_unsafe(&(self.foo()), ::askama::Text),
    expr2 = &::askama::MarkupDisplay::new_unsafe(&(self.bar), ::askama::Text),
)?;

@vallentin vallentin requested a review from djc April 19, 2022 18:34
@@ -1058,11 +1058,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
expr_buf.buf, self.input.escaper
),
};
let is_cacheable = !matches!(s, Expr::Call(..));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this doesn't need to be a "deep" check. E.g. foo().0 should still be uncachable, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, you're right. Guess my quick fix, was too quick. I'll fix it later 😅

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should I review before you fix it or do you want to fix it before I review? Not sure what's more appropriate here.

@djc djc mentioned this pull request Sep 15, 2022
@Kijewski
Copy link
Collaborator

Kijewski commented Sep 17, 2022

Rebased on main. I added Expr::is_cachable() to test the recursive case.

@Kijewski
Copy link
Collaborator

@vallentin, I hope it's okay that I took this over. :)

@djc djc merged commit 7edb3d4 into main Sep 19, 2022
@delete-merged-branch delete-merged-branch bot deleted the skip-cache-calls branch September 19, 2022 10:33
@djc
Copy link
Collaborator

djc commented Sep 19, 2022

Thanks!

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.

3 participants