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

Request String + Data Non-Caching Templating Partial Function #11154

Closed
hollowaykeanho opened this issue Jun 23, 2023 · 4 comments
Closed

Request String + Data Non-Caching Templating Partial Function #11154

hollowaykeanho opened this issue Jun 23, 2023 · 4 comments

Comments

@hollowaykeanho
Copy link

hollowaykeanho commented Jun 23, 2023

Request

Basically to replace this:

        {{- $filename = printf "deletable-%v-%v-%v-%v"
                                (mod (add (mul 13 now.Unix) 97) 400000)
                                (sha256 (string $Page.URL.Current.Absolute))
                                (now.Format "200601021504050700")
                                (crypto.FNV32a $dataList)
        -}}
        {{- $dataList = resources.FromString $filename $dataList -}}
        {{- $dataList = resources.ExecuteAsTemplate $filename $Page $dataList -}}
        {{- $dataList = string $dataList.Content -}}

Reason

  1. Existing solution is causing a "memory leak" phenomenon and no tool is available for investigation (see discource: https://discourse.gohugo.io/t/how-to-memory-profile-in-hugo-server/44728/1) and GitHub Issue "Memory Leak" Problem from hestiaHUGO ZORALab/Hestia#106.
  2. This function is so powerful that it eliminates the need of shortcode and markdown layers of rendering entirely which speeds up and simplify the content generation process. The only problem with this is its undesirable auto-caching nature. (see discource: https://discourse.gohugo.io/t/how-to-instruct-hugo-pipe-not-to-cache/44467/6).

Severity

The memory leak phenomeon can occupy all the memory space and even get into swap. The only way to use is to periodically kill hugo server and restart it.

@bep
Copy link
Member

bep commented Jun 24, 2023

I have no idea what this issue is about, so you need to make it more clear with some examples. And please inline them and not link to some discussion somewhere on the internet.

@hollowaykeanho
Copy link
Author

hollowaykeanho commented Jun 24, 2023

Basically, I'm requesting a partial function that is doing a Go template function against a given string, returning a string, without caching. Right now, I'm using hugo pipe to do the work as shown above.

The problem is hugo pipe did unnecessary caching and somehow the caches are not released back to garbage collector even hitting the 10 minutes marker, behaving like a "memory leak" seen in C language. It doesn't matter how big your computer's RAM is, it will occupy all the RAM as garbage collector can't recover those unused memory.

We're looking at 21%, then 46%, then 72%, then 100% of 16GB Memory, and then enter swap.
hugo-01

I detected there is a memory related issue here (Go programming language can't possibly "memory leak"). However, as presented in the Discourse discussion, I was not approached by anyone about any usable diagnostic tools to further root cause the problem.

I'm pretty sure it is Hugo Pipe because unfortunately, due to this issue, I was forced to stripped off quite a number of features (auto PWA caching, and etc). Hence, the entire theme is not using partialCached or .Store persistent scratchpad.

Reference function: https://github.com/ZORALab/Hestia/blob/experimental/hestiaHUGO/layouts/partials/hestiaSTRING/Sanitize


Value wise

This function itself can handle string rendering with Go templating which is very powerful that it can remove the need of using Markdown and hugo speicfic shortcode which behaves like partial. So, with this function, the theme developer can only focus on partial functions and create a Go compatible codes that are reusable elsewhere.

I just pre-launch an outcome of my approach here: https://hestia.zoralab.com/ which proven that this vital function can indeed build good Hugo theme products.


Use Example

Something like Strings.Process (I made this up) :

      {{- $Page := ... some dictionary data -}}

      {{- $ret := Strings.Process $Page "This page is: {{ .Page.Permalink -}}" -}}

      {{- warnf "%v\n" $ret -}}
----
The page is: http://localhost:8080/
----

Instead of:

        {{- $Page := ... some dictionary data -}}

        {{- $ret :=  "This page is: {{ .Page.Permalink -}}" -}}
        {{- $filename = printf "deletable-%v-%v-%v-%v"
                                (mod (add (mul 13 now.Unix) 97) 400000)
                                (sha256 (string $Page.URL.Current.Absolute))
                                (now.Format "200601021504050700")
                                (crypto.FNV32a $ret)
        -}}
        {{- $ret = resources.FromString $filename $ret -}}
        {{- $ret = resources.ExecuteAsTemplate $filename $Page $ret -}}
        {{- $ret = string $ret.Content -}}
        {{- warnf "%v\n" $ret -}}
----
The page is: http://localhost:8080/
----

@hollowaykeanho
Copy link
Author

Close this ticket since I'm no longer deploying Hugo.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants