Page MenuHomePhabricator

Typing into long documents is very slow (quadratic worst case?)
Closed, ResolvedPublic

Description

Typing into long documents is very slow.

For example: https://en.wikipedia.org/wiki/Intercollegiate_sports_team_champions?veaction=editsource (reported here: https://www.mediawiki.org/wiki/Topic:U8kj6nbqxpc982gy)

This has 400k+ characters across 10k+ paragraphs. On my machine, typing a letter anywhere in the document takes longer than a second.

Event Timeline

Quick profiling reveals that most of the time is spent in ve.dm.TreeCursor.prototype.checkLinearOffset. This function is apparently called twice per paragraph, and it adds up the lengths of all paragraphs preceding it, thus the quadratic performance.