It happens once in a while that a colleague mentions their text editor of choice choking on some large file. Whenever this happens I'm reminded of this excellent series of posts in the docs of the xi text editor. It is a stellar example of the importance of choosing your data structures carefully and reframing a problem until you've found the simplest solution. I highly recommend giving it a read even though it is quite long.
I'm in awe of the level of details in these docs. Furthermore, it is a great introduction to the subtle but really hard problems required to create a modern text editor - that you probably never considered.