I suspect there is no need to use pulseIn() to measure the speed of the fan. However you have not told us what sort of detector you are using to measure the speed.
Also, what is the role of the rotary encoder?
I suspect it would be useful to use the digitalWriteFast() library.
...R