Skip to content

Performance improvement discussion #22

Description

@ewilderj

Hey @xenodium following up on the shell-maker performance issue, I dug a bit deeper.

As I mentioned in agent-shell#403 there are some big table speedups to be had. I won't repeat that data here, but focus on the overlays side of the problem.

The other drag in performance relevant to xenodium/agent-shell#403 is the massive number of overlays that get generated by extended sessions. It is much faster to use text properties where we can.

In long-running agent-shell sessions, Emacs progressively slows down as overlays accumulate. e.g. in a ~530KB buffer, markdown-overlays creates ~9,000 overlays. In practice, users report that above a few thousand overlays, cursor movement, typing, and redisplay become noticeably sluggish. This is one of the root causes behind the high CPU reports in agent-shell#403.

Of the 8,982 markdown-overlays in my example buffer:

Property Count What
face 3,749 Bold, italic, code, source block highlighting
invisible 2,362 Hidden markdown syntax characters
display 602 Table border replacements
before-string 291 Table border prefixes

Source block syntax highlighting alone accounts for ~2,300 overlays — one per highlighted token per character run.

I have been investigating and done both table caching optimizations, and also changes that uses text properties for non-table Markdown fontification. For your perusal they are here:

I am currently testing the combined fix as daily driver. Let me know how you would prefer to sequence these as PRs, as they're pretty much orthogonal. In total there are 3 perf improvements I've readied:

  • convert regexps to constants
  • use text properties not overlays
  • cache tables rather than re-rendering on markdown-overlays-put

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions