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

Excessive CPU and memory usage caused by a wrong syntax (unclosed brackets) #1005

Open
cykuotw opened this issue Nov 25, 2024 · 0 comments
Open

Comments

@cykuotw
Copy link

cykuotw commented Nov 25, 2024

There is probably an unexpected situation due to unclosed brackets that trigger excessive CPU and memory usage in templ fmt and templ generate.

I have a templ component defined as

templ SplitRule(user types.GroupMember, members []types.GroupMember)

When I call it in another templ file but accidentally forget to close the brackets like:

@SplitRule(types.GroupMember{
    UserID:   uuid.NewString(),
    Username: "user me",
}, []types.GroupMember{
    {
    UserID:   uuid.NewString(),
    Username: "user 1",
    },
// })  <------ should be here but I accidentally forget

There are two cases that can trigger the excessive CPU and memory usage:

  1. save the code in VSCode and trigger templ fmt
    • resolve: disable/uninstall templ-vscode vscode plugin and reload vscode
  2. use templ generate
    • resolve: kill terminal process

Both of the 2 latest versions can reproduce the problem.

Just in case you want to reproduce it, here is the repo and here is the file

Snapshots

  • top -i output,
    image
  • templ generate -v output
    image

templ info output

(✓) os [ goos=linux goarch=amd64 ]
(✓) go [ location=/usr/local/go/bin/go version=go version go1.23.3 linux/amd64 ]
(✓) gopls [ location=/home/cykuotw/go/bin/gopls version=golang.org/x/tools/gopls v0.16.2 ]
(✓) templ [ location=/home/cykuotw/go/bin/templ version=v0.2.793 ]

Desktop:

  • OS: WSL Ubuntu 20.04.6 LTS
  • templ CLI version: v0.2.793
  • Go version: go1.23.3 linux/amd64
  • gopls version: golang.org/x/tools/gopls v0.16.2
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

1 participant