-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(useNow): set 1000ms default interval (#4708) #4709
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
base: main
Are you sure you want to change the base?
Conversation
@@ -31,7 +31,7 @@ export function useNow(options: UseNowOptions<true>): { now: Ref<Date> } & Pausa | |||
export function useNow(options: UseNowOptions<boolean> = {}) { | |||
const { | |||
controls: exposeControls = false, | |||
interval = 'requestAnimationFrame', | |||
interval = 1000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we do this we should also update the @default
in tsdocs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I've corrected it.
I'm not against the change, but I think it's also kind of nice to really default to the "now" time. 🤔 Bildschirmaufzeichnung.vom.2025-04-14.15-47-21.mp4 |
Can you share a minimal reproduction of code that causes the cpu to reach 99%? |
I've added some profilings and my concerns to the original issue: #4708 (comment) TLDR: The amount of precision we have by default creates a perception that is more resource taxing, but |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
As described in issue #4708,
useNow
updates a lot, causing a rather significant performance impact for such a (relatively) small utility. This is even moreso the case when actually doing something with the Date value provided, such as converting it to an internationalised string.I've resolved this by setting the default interval to 1000 ms rather than
requestAnimationFrame
. For the use cases where a higher update frequency is required, it is still possible, but I reckon that for 99.9% of cases, once a second is more than plenty.Additional context
N/A