How to improve emacs performance when view large file?

emacs

Solution

To help with large files, I've installed my own `find-file-hook` which turns on fundamental mode (avoids font-lock), turns off undo, and makes the buffer read-only just to avoid any accidental changes (making unnecessary backups of large files).

(defun my-find-file-check-make-large-file-read-only-hook ()
  "If a file is over a given size, make the buffer read only."
  (when (> (buffer-size) (* 1024 1024))
    (setq buffer-read-only t)
    (buffer-disable-undo)
    (fundamental-mode)))

(add-hook 'find-file-hook 'my-find-file-check-make-large-file-read-only-hook)

Obviously adjust the threshold value as you see fit.

Problem

Emacs sometimes hangs when viewing large file. But it is fast with `(global-font-lock-mode -1)`. I'm using a fork of Prelude. Emacs version: 24.3 cocoa System: OS X 10.8.4 Update: I found `(setq jit-lock-defer-time 0.05)` is a method to improve the scrolling speed.

Original source