Optical quadrature encoder goes out of sync at higher speeds
Optical sensors (phototransistors or photodiodes) have capacitance, and
the 10k pulldown resistor is making an RC time constant.   If you want
fast operation, consider using a smaller pulldown, and (there will be
a lessening of output potential) amplifying the signal with a comparator
instead of using it directly for logic.   A threshold around 100 mV might
be appropriate, one LM393 dual comparator would work for both signals.
It's not clear what components your 'D2&quot; and &quot;D3&quot; are, but photodiodes would
be in opposite polarity; could these be phototransistors?
A possible circuit would be like this:



simulate this circuit &ndash; Schematic created using CircuitLab