Skip to content

Add an immutable rope based textbuffer#201

Merged
dannypsnl merged 8 commits intojeapostrophe:masterfrom
6cdh:treelist-editor
Mar 26, 2026
Merged

Add an immutable rope based textbuffer#201
dannypsnl merged 8 commits intojeapostrophe:masterfrom
6cdh:treelist-editor

Conversation

@6cdh
Copy link
Copy Markdown
Collaborator

@6cdh 6cdh commented Mar 22, 2026

This PR

  • Remove the direct framework-backed editor in doclib/editor.rkt.
  • Add immutable rope textbuffer and enable for all supported Racket versions.

It also avoids loading framework module, remove the requirement for xvfb-run in headless environment. And improves startup speed and memory footprint.

The treelist based implementation I experimented is still too slow for big files.

6cdh added 2 commits March 22, 2026 18:39
Restrict end position not exceed the line count of the textbuffer.
Comment thread doclib/editor-legacy.rkt Outdated
@6cdh 6cdh changed the title Add treelist based textbuffer Add an immutable rope based textbuffer Mar 24, 2026
@6cdh
Copy link
Copy Markdown
Collaborator Author

6cdh commented Mar 24, 2026

This will be one of the most exciting changes.

  • Removed GUI dependency
  • Faster textbuffer implementation
  • Immutable textbuffer that is very useful for our heavy concurrent use cases
  • The new rope-based text buffer implementation can be reused by make a immutable interval map, it will be useful for other services in the future.
  • Reduced memory footprint from 400+MB to 200+MB.
  • Faster startup time: 1.7s -> 0.9s

@6cdh
Copy link
Copy Markdown
Collaborator Author

6cdh commented Mar 24, 2026

For performance, the benchmark result using bench/run-editor-bench.rkt:

-backend: legacy
-module: /home/lcdh/work/racket-langserver/doclib/textbuffer/editor-legacy.rkt
+backend: rope
+module: /home/lcdh/work/racket-langserver/doclib/textbuffer/editor-rope.rkt
 fixture: lines=2000 width=40 chars=82000

 build editor from source text
 iterations: 50
-cpu: 6368 ms real: 6416.571 ms gc: 715 ms avg-real: 128331.426 us
+cpu: 18 ms real: 18.439 ms gc: 0 ms avg-real: 368.779 us

 copy editor snapshot
 iterations: 100
-cpu: 9424 ms real: 9498.749 ms gc: 1340 ms avg-real: 94987.488 us
+cpu: 0 ms real: 0.093 ms gc: 0 ms avg-real: 0.930 us

 line/char->pos middle
 iterations: 10000
-cpu: 8 ms real: 8.677 ms gc: 0 ms avg-real: 0.868 us
+cpu: 2 ms real: 2.803 ms gc: 0 ms avg-real: 0.280 us

 pos->line/char middle
 iterations: 10000
-cpu: 13 ms real: 13.161 ms gc: 0 ms avg-real: 1.316 us
+cpu: 2 ms real: 2.810 ms gc: 0 ms avg-real: 0.281 us

 get-char middle
 iterations: 100000
-cpu: 112 ms real: 113.493 ms gc: 0 ms avg-real: 1.135 us
+cpu: 12 ms real: 12.887 ms gc: 0 ms avg-real: 0.129 us

 get-text full document
 iterations: 200
-cpu: 658 ms real: 663.656 ms gc: 4 ms avg-real: 3318.281 us
+cpu: 102 ms real: 103.083 ms gc: 1 ms avg-real: 515.417 us

 get-text middle range
 iterations: 5000
-cpu: 20 ms real: 20.099 ms gc: 0 ms avg-real: 4.020 us
+cpu: 5 ms real: 5.921 ms gc: 0 ms avg-real: 1.184 us

 single top-of-file insert with restore
 iterations: 2000
-cpu: 228 ms real: 230.751 ms gc: 0 ms avg-real: 115.375 us
+cpu: 7 ms real: 7.542 ms gc: 0 ms avg-real: 3.771 us

 single middle replacement with restore
 iterations: 2000
-cpu: 501 ms real: 505.195 ms gc: 0 ms avg-real: 252.597 us
+cpu: 20 ms real: 21.138 ms gc: 0 ms avg-real: 10.569 us

 small multiline replace with restore
 iterations: 1000
-cpu: 343 ms real: 346.685 ms gc: 1 ms avg-real: 346.685 us
+cpu: 10 ms real: 10.841 ms gc: 0 ms avg-real: 10.841 us

 typing burst of 50 inserts with restore
 iterations: 100
-cpu: 363 ms real: 366.392 ms gc: 0 ms avg-real: 3663.916 us
+cpu: 16 ms real: 16.392 ms gc: 0 ms avg-real: 163.923 us

@6cdh
Copy link
Copy Markdown
Collaborator Author

6cdh commented Mar 26, 2026

In CI, removing the GUI dependency and adding the -j flag to raco test cut test runtime from 50s to 14s. It's 7s on my machine. This will make iteration significantly faster.

@6cdh 6cdh marked this pull request as ready for review March 26, 2026 09:50
@6cdh 6cdh requested a review from dannypsnl March 26, 2026 09:50
@dannypsnl dannypsnl merged commit 3fa2508 into jeapostrophe:master Mar 26, 2026
10 checks passed
@6cdh 6cdh deleted the treelist-editor branch March 26, 2026 11:52
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