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

tpl/debug: Add debug.Timer #11581

Merged
merged 1 commit into from
Oct 20, 2023
Merged

tpl/debug: Add debug.Timer #11581

merged 1 commit into from
Oct 20, 2023

Conversation

bep
Copy link
Member

@bep bep commented Oct 19, 2023

Closes #11580

@bep bep force-pushed the feat/timer-11580 branch 4 times, most recently from f654fa4 to 6b7ba4e Compare October 19, 2023 09:32
@jmooring
Copy link
Member

Oh wow. And you can pass it around in context. Nice.

{{ $t := debug.Timer "TestSeq" }}
{{ partial "foo.html" (dict "page" . "timer" $t) }}

@bep bep force-pushed the feat/timer-11580 branch 2 times, most recently from 7b52c8b to 0019548 Compare October 19, 2023 10:22
@bep
Copy link
Member Author

bep commented Oct 19, 2023

Oh wow. And you can pass it around in context. Nice.

I don't see how useful that would be in its current form:

  • The names are global and only the first .Stop will have an effect.
  • The timers are only created and logged if log level is <= INFO
  • The timings gets printed sorted with the slowest last (which I find helpful)

Does the above make sense?
Also, does the debug.Timer naming make sense? I thought about putting it in the time package, but I changed my mind.

@bep bep requested a review from jmooring October 19, 2023 10:29
@bep bep force-pushed the feat/timer-11580 branch from 0019548 to a045b51 Compare October 19, 2023 10:30
@bep bep force-pushed the feat/timer-11580 branch from a045b51 to 5541ec4 Compare October 19, 2023 15:54
@jmooring
Copy link
Member

I agree this should live in the debug package.

My thought on starting the timer in template A and stopping in template B was about following the chain with a single page site, but the --templateMetrics --templateMetricsHints flags already provide the important information, and the result is statistically meaningul (pages > 1).

It did make me think about page-attached timers though, which I suppose we can already do by stuffing time.Now into a scratch.

@bep
Copy link
Member Author

bep commented Oct 20, 2023

It did make me think about page-attached timers though, which I suppose we can already do by stuffing time.Now into a scratch.

Then I'd just put a timer at the top of single.html and stop it at the end, but I don't think that is particulary useful. The typically use case for this is to pinpoint performance bottle necks. I used this yesterday to easily identify a "hot loop" where I did way too much work, and shaved 70% off the build time.

@bep bep merged commit 5160c7e into gohugoio:master Oct 20, 2023
Copy link

This pull request 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 Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add debug.Timer
2 participants