Skip to content

Fontification is too inefficient #1177

Closed
@mrkkrp

Description

@mrkkrp

Haskell mode currently has inefficient fontification:

- redisplay_internal (C function)                                5604  78%
 - jit-lock-function                                             5473  76%
  - jit-lock-fontify-now                                         5465  76%
   - jit-lock--run-functions                                     5463  76%
    - run-hook-wrapped                                           5463  76%
     - #<compiled 0xf8e011>                                      5463  76%
      - font-lock-fontify-region                                 5463  76%
       - font-lock-default-fontify-region                        5454  76%
        - font-lock-fontify-keywords-region                      4574  64%
         + #<lambda 0x2e9b41e>                                   4321  60%
         + eval                                                   101   1%
           whitespace-trailing-regexp                              10   0%
        - font-lock-fontify-syntactically-region                  827  11%
         + syntax-propertize                                      706   9%
           syntax-ppss                                              3   0%
        - font-lock-unfontify-region                                3   0%
           font-lock-default-unfontify-region                       3   0%
 + eval                                                           128   1%
   file-remote-p                                                    3   0%
+ command-execute                                                 778  10%
- ...                                                             680   9%
   Automatic GC                                                   676   9%
 + flycheck-buffer-automatically                                    4   0%
  sml/generate-position-help                                       18   0%
+ timer-event-handler                                              16   0%
+ flycheck-display-error-at-point-soon                             11   0%
+ undo-auto--add-boundary                                           7   0%
+ yas--post-command-handler                                         4   0%
  internal-timer-start-idle                                         4   0%
  delete-selection-pre-hook                                         3   0%

Try it yourself — set quite high frequency of key repeat on OS level and hold a key when is Haskell mode. You will see that dislay update is sporadic (well, of course you should turn off Smartparens and Flyspell, because they skyrocket typing latency). Compare with Emacs Lisp mode where characters appear continuously.

My understanding is that the higher time spent in GC the “slower” the experience. In Emacs lisp mode 5% of time is spent in GC even with aggressive indent enabled. Here we have 10 % and it turns out it's quite high already. In markdown mode it's 20% and it's unbearable (under certain conditions).

Why this matters? Typing with little latency in responsive editor is a joy. In Emacs, many packages use hooks that are executed after every key press (there are a number of them) plus some modes have inefficient fontification that actually makes “advanced” Emacs setup slower than some IDEs. It can get really slow. Web-based Atom text editor feels faster. In Haskell mode when everything sums up, it lags when I type fast.

Now I decided that I either switch to different text editor or make my Emacs as fast as it is when it's vanilla. I would really like to succeed in the latter.

And here is an article for you:

https://pavelfatin.com/typing-with-pleasure/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions