lazy.nvim icon indicating copy to clipboard operation
lazy.nvim copied to clipboard

feat(stat): use cputime for all timing related functions

Open jdrouhard opened this issue 11 months ago • 1 comments

Description

It's always baffled me why the 3 timings at the top of the Profile tab didn't match the individual timings of the profiles in the more detailed breakdown in the lower section. Decided to dive into this a bit and realized that cputime was being used for the main 3, but relative timings from one stage to the next were using vim.uv.hrtime() - <prev_snapshot>.

These are two different types of timings. I may have some changes soon that attempt to remedy this, but if the cputime() function is using the ffi clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...) from the OS, it measures only the cpu time of the process, not the wall time from process start to the time of the call. Unfortunately this means the cputime measurement doesn't reflect actual elapsed time. When you mix and match these two, the times don't add up.

This PR aims to unify the times in the profile output so all the shown elapsed times are sourced by the same method. It moves cputime() to lazy.core.util and changes the stats' times[] to store nanoseconds instead of milliseconds.

jdrouhard avatar Jan 23 '25 19:01 jdrouhard

This PR is stale because it has been open 30 days with no activity.

github-actions[bot] avatar Feb 24 '25 02:02 github-actions[bot]