[issue4965] Can doc index of html version be separately scrollable?

Ezio Melotti report at bugs.python.org
Tue Oct 15 03:18:37 CEST 2013


Ezio Melotti added the comment:

I've looked into it, and I found that:
1) the scroll event can be triggered dozens of times per second;
2) sidebarwrapper.css(...) causes a browser repaint/reflow, which is slow;

Optimizing the function doesn't seem like a good solution, so I tried to throttle it so that the position is updated at most once every 100ms (i.e. at 10fps max).  On Firefox this shows that about 2-6 redraws are skipped but, as a side-effect, the sidebar might result a few pixels off due to the skipped redraws at the end (this doesn't seem noticeable though).
If the value is increased over 100ms these problems start being noticeable.

FTR there are more complex solutions but for now I preferred to keep it simple.  These links contain other techniques (involving timers/timeouts):
* https://github.com/shichuan/javascript-patterns/blob/master/jquery-patterns/window-scroll-event.html
* http://underscorejs.org/docs/underscore.html#section-66 and http://underscorejs.org/#throttle

Serhiy, can you try to apply the patch and fiddle a bit with it to see if you notice any improvement?  You can try to change 100 with a lower or higher value, or do last_call = new Date() at the end of scroll_sidebar().  You might also have to remove the calls to console.log() if they create problems on your browser.
Remember that after each change you have to do:
  cp Doc/tools/sphinxext/static/sidebar.js Doc/build/html/_static/sidebar.js
and refresh the page to see the results.

----------
Added file: http://bugs.python.org/file32128/issue4965-throttle.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4965>
_______________________________________


More information about the Python-bugs-list mailing list