Synchronizing two scrollbars to work in unison
This looks perfectly good to me.  Everything has a unique purpose, everything is either clearly explained or self-explanatory.  Unless you have tested this and found a performance issue, and you are sure that it is happening here, do not do any optimization to this.  

There is no loop and no recursion, the code itself can't properly be an optimization target.  If you are observing that this is running slowly, the hidden costs of setting the scrollbars must be the cause.  To address this you will need to change your entire strategy to keeping the div contents in the right place using CSS only.  I have to say that while I find using the position of some element (scrollP?) to be a pretty elegant way to duck issues of messing around with coordinates that will be inconsistent otherwise, it is technically the best practice to do all positioning with CSS.