-
-
Notifications
You must be signed in to change notification settings - Fork 297
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
Taking too much memory with (relatively) larger files #916
Comments
Thanks for raising that. I'd have to take a look at a memory profile to see where all that RAM is being used, and whether any of it can be reclaimed more aggressively. For your library (cool idea, by the way!), the best approach might be to use the Go If you drop the package templicons
import (
"context"
_ "embed"
"io"
)
type IconComponent []byte
func (ic IconComponent) Render(ctx context.Context, w io.Writer) (err error) {
_, err = w.Write(ic)
return err
}
//go:embed icons/3dGlasses.svg
var Glasses3D IconComponent
//go:embed icons/3dHammer.svg
var Hammer3D IconComponent |
Thank you for your time and your grate work!
Thanks but it is unfortunately not my idea actually🫣 I'm just trying to replicate React Icons in go and templ
I really appreciate the suggestion! I'll definitely consider that and see how it goes. |
Unfortunately I couldn't figure out a good way using your suggested approach so I went back to my original (dumber) approach😅... For anyone interested, the library is now somehow usable.. GitHub repo | GitLab repo, and the really bad code that generates it all can be found here P.S: Even the gitlab ci/cd machine(same 8GB RAM but no desktop/browser/editor/etc.. running like my laptop) couldn't handle the larger icon sets(3k+ icons) and the process keep getting killed after about half an hour or so |
I just ran pprof and collected a heap dump... seems like the issue is that goexpression.Func() tries to parse the same file over and over again. The current logic seems to be:
So in the sample file, the first run of goexpression.Func() gets the whole file, then the whole file minus first template, then whole file minus first two templates etc. On the screenshot, the root cause seems to be the When you combine the above, the memory consumption becomes The logic is a bit wasteful for the CPU (it's best to astparse one file exactly once), but there is a hotfix for the mem leak itself. I'll push the MR in a second. |
Just tested it - the sample repo takes 47 seconds and near-constant RAM on my laptop :) |
Describe the bug
I'm not sure if this is normal/expected or a known issue so sorry in advance about my ignorance.
When I try to
templ generate
a single (programmatically generated) 6.4MiB .templ file which contains 4048templ
definitions each one is an svg from Game Icons, it takes all the available memory and the laptop starts lagging and even if I leave it like this for a long time it won't finish and the memory consumption will lower sometimes to like 2GB then go back to taking all the available memory..Also the LSP(vscode with the templ extencion) does the same thing when I open the same file in vscode.
To Reproduce
Clone this repo and run
templ generate
in it.Expected issue cause
I'm not familiar with the templ codebase but I think it may be in issue in a parser of some kind (may be specific to SVG parsing).
Screenshots
![templmem](https://private-user-images.githubusercontent.com/84265453/366428927-bb1d94cc-907f-4f93-b77e-3b682614e83e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0ODQwNDcsIm5iZiI6MTczOTQ4Mzc0NywicGF0aCI6Ii84NDI2NTQ1My8zNjY0Mjg5MjctYmIxZDk0Y2MtOTA3Zi00ZjkzLWI3N2UtM2I2ODI2MTRlODNlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDIxNTU0N1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2YjczMzYxZWExMDk4MDJmZjYyMmRkMDM5NzNlNmI5NTU0NTFhNmRkZTg3MzJkZTRmNmUyYTgyZDM4ZDdhM2EmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.msMtHinnCqv_oExhzQch4b3djtSEJOR1fNhM4UpyUHA)
templ info
outputDesktop:
gopls
version: golang.org/x/tools/gopls v0.16.2The text was updated successfully, but these errors were encountered: