Skip to content

Conversation

@Azeirah
Copy link

@Azeirah Azeirah commented Jan 25, 2026

The existing implementation is O(n^2) in the number of nodes. That's fine for drawings, but it takes minutes to process big text documents because the reMarkable creates a node for each word.

This patch implements Kahn's algorithm. That would ordinarily be O(n), but to maintain deterministic ordering for concurrent edits (as the current algorithm does), we use a heap instead of a set, making the runtime O(n log n).

My text-heavy notebook now processes in about a second instead of minutes.

Original PR here: ricklupton#49

The existing implementation is O(n^2) in the number of nodes. That's fine for drawings, but it takes minutes to process big text documents because the reMarkable creates a node for each word.

This patch implements [Kahn's algorithm](https://en.wikipedia.org/wiki/Topological_sorting#Kahn's_algorithm). That would ordinarily be O(n), but to maintain deterministic ordering for concurrent edits (as the current algorithm does), we use a heap instead of a set, making the runtime O(n log n).

My text-heavy notebook now processes in about a second instead of minutes.
@Azeirah Azeirah merged commit 0e1a314 into Scrybbling-together:main Jan 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants