templ
templ copied to clipboard
-watch ... CPU core 100% usage
Noticed a interesting bug when using "templ generate -watch"...
If you keep the watch active, after some time (a hour, several hours ...) the CPU fans start to spin up. Checking htop shows that the ""templ generate -watch" CPU usage hits 100%.
Restarting the process fixes the issue. Not entirely sure what causes this issue, as templ is also not showing any error.
Its hard to pinpoint when or why it happens as it mostly triggers after a long period. Seen this happen now at minimum 7 times. But because the above issue of hours passing by, and only noticing when the CPU fan spins up (after a while of heat buildup), the actual trigger event is a big mystery.
Setup: WSL2 + Debian + VSC [Task "templ generate -watch"]
This is going to be one of "those" tickets that your going to remember in a few months upon finding some rare bug ;)
Have noticed this happening too - shifting to a different process to handle file watching as I notice it when my battery warning comes up 😭
Setup: MacOS + zsh + templ generate -watch
Thanks for bringing it up. It was discussed in https://github.com/a-h/templ/discussions/302 and I believe it to be fixed in https://github.com/a-h/templ/pull/309
Basically, after 15 minutes, the backoff process decides that it's done as much backing off as it was ever going to do, and then starts smashing filesystem lookups.
If you're able to try out the current main branch and verify it's fixed, that would be helpful!
Hi @a-h. Is there an easy way to try out the main branch? (apologies - bit of a Go newb.) I think I've just encountered this issue - my laptop sounded like it was about to take off 😆
@lllama, yes there is!
Using Go tools you can install any commit into your path with go install
. This command uses your current Go version to build the binary.
go install github.com/a-h/templ/cmd/templ@f7d965c4412b255f8ac9c8547c4f083a2b353e03
On my system, it puts the templ binary into ~/go/bin
.
If you like Nix, you can do the same with that. nix shell github:a-h/templ/f7d965c4412b255f8ac9c8547c4f083a2b353e03
will start you a shell with that commit of templ inside it. However, it uses the Go version that's set in the flake.nix
and flake.lock
file, not the version of Go that's installed on your system, and therefore more exactly reproduces the CI pipeline's build.
I should also have mentioned that if you use a later version of templ to generate code than you have imported into your project, you might get compile time errors on the generated code.
With Go, if you do go get github.com/a-h/templ
, you'll get the latest tagged version of templ.
If you want to use a specific commit as the runtime portion of templ, you can use similar syntax to go install
:
go get github.com/a-h/templ/cmd/templ@f7d965c4412b255f8ac9c8547c4f083a2b353e03
I'm still experiencing high (100%) CPU on templ --watch
(Linux AMD 64). Before and after upgrading to v0.2.501
I don't have those issues on macOS anymore. I've upgraded both the CLI (go install github.com/a-h/templ/cmd/templ@latest
) and the package (go mod
handled that for me I think). I have multiple (3) watchers running in parallel and none is causing issues anymore - they did before I've upgraded.
The templ
version I'm using is v0.2.513
.
Thanks for that @rokf - it's very helpful to hear that you were having issues before, but that these have been resolved by the recent changes.
Could be related: https://github.com/a-h/templ/issues/418