Break your code into ‘pure’ functions, and cache their results.
Limit the rate at which a function can be called.
Don’t execute a function until it hasn’t been called in a while.
Create a function that only calls its implementation once.
Let pending user actions take priority over this function call.
Collect all the changes a script wants to make, and run them in a single pass
Batch up DOM writes and reads for minimal layout steps.