Hi Michal,
I had one more doubt.
Case 1:
onClick={ () => {
criticalTask(); // a UI update, takes 200 ms for execution
requestAnimationFrame( () => {
setTimeout( () =>
nonCriticalTask(); // some GA trackings, takes 30 ms for execution (using setTimeout only would have also worked here )
,0);
}
}
}
INP in case 1:
Input delay: 40 ms
Processing time: 200 ms
Presentation delay: 30 ms
Overall INP: 270 ms
Here overall time taken for the visual update would be close to 270 ms.
-----------------------------------------------------------------------------------------
Case 2:
onClick={ () => {
nonCriticalTask(); // some GA trackings, takes 30 ms for execution
requestAnimationFrame( () => {
setTimeout( () =>
criticalTask(); // a UI update, takes 200 ms for execution
,0);
}
}
}
INP in case 2:
Input delay: 40 ms
Processing time: 30 ms // targeting processing time
Presentation delay: 30 ms
Overall INP: 100 ms
Here, the overall time taken for the visual update would be as:
INP
+
criticalTask() // 200 ms execution time
+
time taken to execute setTimeout in the event loop // roughly 30 ms in my case
Overall visual feedback time= 100 +200 +40 = 330 ms // 270 ms in case 1
Here by implementing case 2 user is not experiencing any delay in the UI update as visual feedback got delayed by a factor of 50 - 60 ms only.
--------------------------------------------------------------------------
So I just want to know if this case 2 implementation is a good/ethical way to reduce INP ?
Please share your valuable input.
Thanks
Abhishek