FastDOM - a small library that batches DOM reads & writes into raf (requestAnimationFrames).
https://github.com/wilsonpage/fastdom
I have read the code, however, I am struggling to understand how it works. Here are a few presumptions we have: - Browsers are generally set to 60fps - So in total, there can be a maximum of 60raf in a sec
That is to say that each FastDOM read / write batch would run after 17ms (1000 ms / 60 fps). Would that not be very slow as a function may have read / write calls one after the other?
Clearly the above is not the case, however, Im confused and would be grateful for clarification.
Thanks,
Both types of DOM operations (read/write) have their own job queues. Each queue is flushed (e.g. all jobs in it are ran/executed) every
requestAnimationFrame
If you add 100 read operations all within 5ms, for example, (during a loop for instance), all of those read operations will (most likely) occur the next time the
read
queue is flushed (which could be 1ms after the last job is added, or 16.66667ms after the last job is added).Read through the source, it's well written and well commented.