Sublime Forum

Curious about sublime internals

#1

Hello, i understand that this is forum is for technical support for sublime users so my post don’t really fit here.

As a programmer, I’m just fascinated by sublime text’s performance and its text quick processing, And if its not a secret, i wanna know how it does that

For example, it can edit 500MB file without any lag.
What data structure does it use to store its internal text?
Here are the possibilities:

  • array of heap allocated lines
  • gap buffer
  • btree
  • rope

My guess is it probably uses something line-based cause it editing does lag on big lines

Respectfully, to sublime devs.

2 Likes

#2

First thing to know is we integrate syntax highlighting with text storage, meaning we don’t store text directly in our data structure but instead first perform syntax highlighting which generates tokens that we then store. Our data structure is similar to a rope: leaves store an array of tokens and intermediate nodes store metadata of their children. Unlike a rope this structure is entirely mutable.

The reason editing long lines is slow is not due to the data structure but because syntax highlighting is done on a per-line basis; so each edit needs to retrieve the whole line, perform syntax highlighting and then insert it back into the data structure.

3 Likes