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

Cache rendered template #12

Closed
megafinz opened this issue Oct 29, 2018 · 7 comments
Closed

Cache rendered template #12

megafinz opened this issue Oct 29, 2018 · 7 comments

Comments

@megafinz
Copy link

Seems like Fue is compiling the template each time I call it (I'm using fromText), even if it doesn't change (except the data). This generates a lot of unneeded memory traffic which I'd like to avoid. Is there any way to reuse the compiled template?

@Dzoukr
Copy link
Owner

Dzoukr commented Oct 31, 2018

Hi @megafinz, yes you are right, it does it on each call. I will think about it, but you know - proper caching is hard. 😄 This would introduce some kind of state inside of library. I really need to think about it. Any help (even good idea) here is more then welcome.

@petejohanson
Copy link
Contributor

Doesn't partial application get you this "for free" ?

e.g.

use Fue.Compiler
use Fue.Data

let someTemplate: Map<String, object> -> string = fromFile "SomeTemplate.txt.fue"

let a = init |> add "name" "Bob" |> someTemplate
let b = init |> add "name" "Jones" |> someTemplate

@megafinz
Copy link
Author

@petejohanson Not really. When you apply partial application, the function is not being executed, it's just becoming a function with an embedded param. It's the same as if you were passing that filename directly in each call.

petejohanson added a commit to petejohanson/Fue that referenced this issue Dec 14, 2018
* Switch to not relying on auto-currying, but intentional pre-load/parse
  then return resulting template function, so we can partially apply
  fromText/fromFile and re-use the templates. Fixes Dzoukr#12.
@petejohanson
Copy link
Contributor

@megafinz Indeed, the current implementation relying on auto-currying does not work as I had outlined. See my PR which adjusts things so that it does in fact work as expected w/ partial application creating a pre-loaded "template function" that can be re-used and won't re-load/parse the template string/file.

@petejohanson
Copy link
Contributor

PS: @Dzoukr thanks for a nice codebase that works OOTB when using .NET Core on Linux!

@petejohanson
Copy link
Contributor

PPS: Pondering this a tad more, you could argue, if weakly, that this is a breaking change in behaviour, if consumers of Fue previously relied on partial applications of fromFile to re-parse the file on each invocation. I'd defer to @Dzoukr as to whether he considers that part of the implicit contract for this API or not when it comes to how to treat this change, if merged, as affecting SemVer. API unchanged, underlying behaviour subtly changed.

@Dzoukr
Copy link
Owner

Dzoukr commented Dec 15, 2018

Hi @petejohanson & @megafinz, I just merged changes from PR. Let me check few tests and we can publish new version. I agree with @petejohanson that it is subtle change and behavior should be actually like that from very beginning.

Dzoukr added a commit that referenced this issue Dec 15, 2018
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

No branches or pull requests

3 participants