Emacs line numbering performance
Asked Answered
B

4

6

I've tried linum and nlinum. Both have dreadful performance on files with 100k+ lines.

$ for x in {1.100000}; do echo $x; done > 100k.txt
$ emacs -q 100k.txt
M-x load-library linum
M-x linum-mode
M-> ;; it's not too bad to go to end of file
M-< ;; now this completely locks up emacs

The same operation with editors like joe is instantaneous.

Is there any solution other than to turn off line numbers with big files (exactly the type of files that you want to navigate with line numbers - I have in mind locating error lines in concatenated Javascript files)?

Or just use a different editor?

Brachiopod answered 3/10, 2013 at 11:15 Comment(10)
The line number is shown in the mode line.Ruprecht
This is instantaneous for me on Emacs 24.3.50.1Tangible
@Tangible it is not instantaneous for me, running 24.3.1 on Ubuntu precise 3.5.0-40-generic, and with default config loaded (as you can see, I'm using -q). Running in rxvt window.Brachiopod
@Ruprecht the mode line is too big a visual gap to be scanning back and forth between cursorBrachiopod
@Tangible I'm using Damien Cassou's PPA to get a semi-recent emacs on Ubuntu. Do you know how I can get yet a more recent version without having to build it myself?Brachiopod
I've found that emacs bug 14259 is relevant, reported in April. Simply setting window margin is enough to trigger slowdown ((set-window-margins (selected-window) 2))Brachiopod
@BarryKelly sorry, I build my own from the bzr repo, running Debian. Not sure what's available for Ubuntu.Tangible
I can't reproduce it with Debian's 24.1 nor with Emacs's trunk (only tested with nlinum.el).Sentimentalize
I'm using the regular Emacs 24.2.1 package on Ubuntu 13.04 and can't reproduce this problem, neither with Emacs running in its own graphical frame nor in a gnome-terminal.Grandiose
@Rörd I'm on Ubuntu 12.04 LTS. It's not just me, see lists.gnu.org/archive/html/bug-gnu-emacs/2013-04/msg00577.htmlBrachiopod
T
5

I think you found a bug, and you may report (report-emacs-bug) it. As per Tyler comment, it may have been already solved.

Things that may help you in the meanwhile... line-number-mode, goto-line, narrow-to-region and this cheapo-number-my-lines-in-a-tmp-buffer trick:

(shell-command-on-region (point-min) (point-max)
    (concat "grep -n ^ " buffer-file-name)
    (get-buffer-create "*tmp-linum*") nil t)
Topliffe answered 3/10, 2013 at 12:52 Comment(0)
P
4

As far as I know, both linum and its derivative nlinum number lines even if you don't see them. In the case of 100k+ lines, this can be slow if numbering an individual line takes more than a few tenths of a millisecond. For me, (Fedora 19, Emacs 24.3.1), there's no noticeable delay. Try line-num.el, which only numbers lines that are currently visible and see if it fixes the problem.

Portage answered 4/10, 2013 at 22:49 Comment(0)
G
1

Since Emacs 26 you should use [global-]display-line-numbers-mode instead.

For example:

(global-display-line-numbers-mode 1)

or:

(add-hook 'prog-mode-hook #'display-line-numbers-mode)

(Or toggle them manually via M-x.)

The line numbering for these is implemented as part of the redisplay in C code, and is therefore efficient and performs well even with extremely large buffers.

To customize this feature use:

M-x customize-group RET display-line-numbers

Greylag answered 30/5, 2022 at 5:25 Comment(0)
L
0

Add this to .emacs file.

(global-linum-mode 1)
Lousy answered 28/5, 2022 at 11:13 Comment(4)
The question discounted linum as too slow.Greylag
The settings for M-x linum-mode and .emacs files are different. I've been using it on centos with this setup so far and it works without any issues.Appleton
@Greylag What is the difference between the method you suggested and mine? I think it is more advantageous to use it by presetting it in the initialization file.Appleton
One can, of course, put (global-display-line-numbers-mode 1) in the init file; I hadn't said that explicitly, but assumed people would know. global-display-line-numbers-mode and global-linum-mode are two very different things. The former is newer and (crucially for this question) very fast (because it's integrated into the core redisplay C code). linum-mode does not have those benefits, and is much slower. The only reason I gave your answer a down-vote was that your suggestion had been specifically mentioned in the question as one of the options which was too slow.Greylag

© 2022 - 2025 — McMap. All rights reserved.