line-number-at-pos (when repeated about 50 times) is causing a noticeable slow-down in semi-large buffers -- e.g., 50,000 lines -- when point is near the end of the buffer. By slow-down, I mean a combined total of about 1.35 seconds.
Instead of using a 100%
elisp funciton to count-lines and goto the top of the buffer, I'd be interested in a hybrid method that taps into the built-in C abilities responsible for the line number appearing on the mode-line. The line-number that appears on the mode-line occurs at light speed, regardless of the size of the buffer.
Here is a test function:
(defmacro measure-time (&rest body) "Measure the time it takes to evaluate BODY. http://lists.gnu.org/archive/html/help-gnu-emacs/2008-06/msg00087.html" `(let ((time (current-time))) ,@body (message "%.06f" (float-time (time-since time))))) (measure-time (let* ( line-numbers (window-start (window-start)) (window-end (window-end))) (save-excursion (goto-char window-end) (while (re-search-backward "\n" window-start t) (push (line-number-at-pos) line-numbers))) line-numbers))