Skip to content

BUG | useNow | Default interval is too performance intensive #4708

Open
@MPFGlaser

Description

@MPFGlaser

Describe the bug

useNow has the option to provide an interval to use for refreshing the 'now' Date. Currently, the default interval is set to requestAnimationFrame, which, if I'm not mistaken, updates the value 60 times per second for a 60hz display (or 144x for 144hz, etc.).
While I'm sure it has its use cases to update the value this often, I feel like it is overkill for the majority of situations. In my project, I've noticed that using the "bare" value produced by this composition utility uses 5%(ish) of my CPU's capacity. Doing any sort of transformation on the data, such as passing it through some i18n magic as is the case with my project, causes the browser to freeze because 100% of the CPU is occupied with updating this one ref.
As such, I propose to set the default interval to 1000 ms, which still leaves the option to increase or decrease it as the user's request, or to use requestAnimationFrame if so desired.
To make life easier if people agree with me, I'll provide a PR that fixes this issue.

Reproduction

https://playground.vueuse.org/#eNp9UbtOAzEQ/JWVG0DKo4AquiAeSgFFQEDp5uTsXRx8tuW1k0On+3f2nAcpUFx5Z2ZnZ7WdePR+sk0oZqIgFbSPQBiTB1Paei5FJCnupdWNdyFCB5AIl24HPVTBNXD1wL0MTZULeCWttMpZimBZMj9or2+kLaZ7c7biImLjTRmRK4BipbegTEnE4yqDLWjmaazQRgywSRR19XMsd2M2QrSwPnxyPODXdTy077PllD0ZLqZnk8SIl+F0la4nG3KWN+4GsRTKNV4bDG8+ak4vxQwyM3ClMW73mrEYEo6OuFqj+v4H31A7YFK8ByQMW5TixMUy1Bj39OJziS3/T2TjVsmw+gL5geRMGjLuZU/Jrjj2mS6nfcm30rb+okUb0dJxqSHooOyzXgo+3fOF1f/i3k7ucp+0veh/AbxmvSc=

System Info

System:
    OS: Linux 5.15 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (14) x64 Intel(R) Core(TM) Ultra 7 155U
    Memory: 8.21 GB / 15.35 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.18.0 - ~/.nvm/versions/node/v20.18.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.18.0/bin/npm
    pnpm: 9.15.5 - ~/.nvm/versions/node/v20.18.0/bin/pnpm

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions