vimamsa 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +139 -89
  3. data/custom_example.rb +18 -6
  4. data/doc/TODO.md +327 -110
  5. data/doc/action_names_plan.md +442 -0
  6. data/doc/bundling_plan.md +2 -1
  7. data/doc/delta_syntax_plan.md +293 -0
  8. data/doc/demo_recording_plan.md +288 -0
  9. data/doc/design_goals.md +27 -0
  10. data/doc/intro_page_plan.md +266 -0
  11. data/doc/key_bindings_report_plan.md +45 -0
  12. data/doc/line_tree_plan.md +89 -0
  13. data/doc/missing_vim_bindings.md +34 -44
  14. data/doc/modules_settings_plan.md +1 -1
  15. data/doc/registries_plan.md +202 -0
  16. data/doc/startup_speed_plan.md +97 -0
  17. data/doc/treap_visualizer.html +585 -0
  18. data/doc/vim_compatibility_plan.md +186 -31
  19. data/doc/vimlike_vim_conflicts.md +236 -228
  20. data/doc/vm_snapshots_plan.md +4 -4
  21. data/doc/wysiwyg_plan.md +231 -0
  22. data/exe/run_tests.rb +8 -1
  23. data/exe/vimamsa +49 -6
  24. data/help/intro.txt +30 -0
  25. data/help/vim_intro.txt +31 -0
  26. data/img/demo.gif +0 -0
  27. data/img/demo.mp4 +0 -0
  28. data/lang/hyperplaintext.lang +1 -1
  29. data/lib/vimamsa/ack.rb +2 -0
  30. data/lib/vimamsa/actions.rb +381 -36
  31. data/lib/vimamsa/bookmarks.rb +8 -8
  32. data/lib/vimamsa/buffer.rb +83 -37
  33. data/lib/vimamsa/buffer_changetext.rb +58 -36
  34. data/lib/vimamsa/buffer_list.rb +2 -2
  35. data/lib/vimamsa/buffer_manager.rb +6 -6
  36. data/lib/vimamsa/cli_help.rb +75 -0
  37. data/lib/vimamsa/clipboard.rb +6 -3
  38. data/lib/vimamsa/conf.rb +9 -0
  39. data/lib/vimamsa/crash_handler.rb +2 -2
  40. data/lib/vimamsa/debug.rb +2 -2
  41. data/lib/vimamsa/demo_player.rb +458 -0
  42. data/lib/vimamsa/demo_recorder.rb +277 -0
  43. data/lib/vimamsa/diff_buffer.rb +1 -1
  44. data/lib/vimamsa/dot_repeat.rb +104 -0
  45. data/lib/vimamsa/easy_jump.rb +54 -3
  46. data/lib/vimamsa/editor.rb +89 -46
  47. data/lib/vimamsa/file_history.rb +1 -1
  48. data/lib/vimamsa/file_manager.rb +23 -23
  49. data/lib/vimamsa/form_input.rb +388 -0
  50. data/lib/vimamsa/gui.rb +83 -13
  51. data/lib/vimamsa/gui_command_line.rb +44 -5
  52. data/lib/vimamsa/gui_form_generator.rb +17 -6
  53. data/lib/vimamsa/gui_key_hint.rb +165 -0
  54. data/lib/vimamsa/gui_keylog_panel.rb +164 -2
  55. data/lib/vimamsa/gui_menu.rb +69 -50
  56. data/lib/vimamsa/gui_select_window.rb +77 -43
  57. data/lib/vimamsa/gui_settings.rb +9 -5
  58. data/lib/vimamsa/gui_sourceview.rb +15 -81
  59. data/lib/vimamsa/gui_theme.rb +11 -2
  60. data/lib/vimamsa/hook.rb +2 -0
  61. data/lib/vimamsa/intro_page.rb +368 -0
  62. data/lib/vimamsa/key_actions.rb +315 -225
  63. data/lib/vimamsa/key_binding_tree.rb +228 -61
  64. data/lib/vimamsa/key_bindings_notepad.rb +18 -16
  65. data/lib/vimamsa/key_bindings_report.rb +290 -67
  66. data/lib/vimamsa/key_bindings_vim.rb +47 -297
  67. data/lib/vimamsa/key_bindings_vimlike.rb +347 -339
  68. data/lib/vimamsa/key_names.rb +80 -0
  69. data/lib/vimamsa/line_tree.rb +367 -0
  70. data/lib/vimamsa/macro.rb +20 -3
  71. data/lib/vimamsa/rbvma.rb +15 -0
  72. data/lib/vimamsa/registers.rb +125 -0
  73. data/lib/vimamsa/run_ruby.rb +64 -0
  74. data/lib/vimamsa/search_replace.rb +4 -4
  75. data/lib/vimamsa/string_util.rb +17 -3
  76. data/lib/vimamsa/tests.rb +8 -8
  77. data/lib/vimamsa/text_objects.rb +11 -54
  78. data/lib/vimamsa/text_transforms.rb +4 -0
  79. data/lib/vimamsa/tmp_user_dir.rb +39 -0
  80. data/lib/vimamsa/user_dirs.rb +83 -0
  81. data/lib/vimamsa/version.rb +1 -1
  82. data/lib/vimamsa/vim_core.rb +355 -0
  83. data/lib/vimamsa/vim_operators.rb +365 -0
  84. data/modules/calculator/calculator.rb +5 -5
  85. data/modules/color_highlight/color_highlight.rb +3 -3
  86. data/modules/dictation/dictation.rb +32 -32
  87. data/modules/ollama/ollama.rb +5 -5
  88. data/modules/terminal/terminal.rb +5 -5
  89. data/modules/tts/tts.rb +10 -10
  90. data/run_e2e_vm.sh +3 -3
  91. data/run_tests_vm.rb +138 -0
  92. data/scripts/demo/demo_easyjump_steps.txt +60 -0
  93. data/scripts/demo/demo_files_steps.txt +52 -0
  94. data/scripts/demo/demo_steps.txt +9 -1
  95. data/scripts/demo/notes.txt +6 -0
  96. data/scripts/demo/record_demo.rb +60 -81
  97. data/scripts/demo/report.rb +7 -0
  98. data/scripts/demo/shapes.rb +1 -0
  99. data/scripts/demo/square/shapes.rb +29 -0
  100. data/scripts/demo/square/steps.txt +185 -0
  101. data/scripts/lib/perf_startup.rb +138 -0
  102. data/scripts/lib/script_helpers.rb +53 -0
  103. data/scripts/perf_compare.rb +34 -0
  104. data/scripts/profile_startup.rb +72 -0
  105. data/tests/test_action_ids.rb +232 -0
  106. data/tests/test_auto_format.rb +2 -2
  107. data/tests/test_autocomplete.rb +1 -1
  108. data/tests/test_basic_editing.rb +18 -18
  109. data/tests/test_bookmarks.rb +6 -6
  110. data/tests/test_bracket_match.rb +3 -0
  111. data/tests/test_cli_help.rb +64 -0
  112. data/tests/test_color_highlight.rb +2 -2
  113. data/tests/test_command_line.rb +1 -1
  114. data/tests/test_context_menu_file.rb +18 -0
  115. data/tests/test_copy_paste.rb +33 -33
  116. data/tests/test_custom_two_phase.rb +1 -1
  117. data/tests/test_demo_player.rb +301 -0
  118. data/tests/test_demo_recorder.rb +202 -0
  119. data/tests/test_dictation.rb +16 -16
  120. data/tests/test_dot_repeat.rb +88 -0
  121. data/tests/test_easy_jump.rb +93 -0
  122. data/tests/test_extract_file_links.rb +3 -3
  123. data/tests/test_file_panel.rb +2 -2
  124. data/tests/test_flash.rb +1 -1
  125. data/tests/test_fold.rb +1 -1
  126. data/tests/test_form_input.rb +203 -0
  127. data/tests/test_func_panel.rb +2 -2
  128. data/tests/test_gtk_sync.rb +7 -7
  129. data/tests/test_intro_page.rb +437 -0
  130. data/tests/test_key_categories.rb +163 -0
  131. data/tests/test_keylog_panel.rb +163 -3
  132. data/tests/test_line_ends.rb +51 -0
  133. data/tests/test_line_tree.rb +86 -0
  134. data/tests/test_lsp_clangd.rb +2 -2
  135. data/tests/test_macro.rb +2 -2
  136. data/tests/test_module_interface.rb +9 -9
  137. data/tests/test_notepad_bindings.rb +5 -5
  138. data/tests/test_perf_startup.rb +28 -0
  139. data/tests/test_random_edit.rb +27 -27
  140. data/tests/test_registers.rb +122 -0
  141. data/tests/test_run_ruby.rb +77 -0
  142. data/tests/test_startup_file.rb +1 -1
  143. data/tests/test_text_objects.rb +1 -1
  144. data/tests/test_text_transforms.rb +12 -0
  145. data/tests/test_tmp_user_dir.rb +79 -0
  146. data/tests/test_tts.rb +10 -10
  147. data/tests/test_undo.rb +34 -34
  148. data/tests/test_user_dirs.rb +122 -0
  149. data/tests/test_vim_bindings.rb +107 -6
  150. data/tests/test_vim_conflicts.rb +41 -4
  151. data/tests/test_vim_operators.rb +116 -0
  152. data/tests/test_window_layout.rb +83 -0
  153. data/vimamsa.gemspec +1 -1
  154. data/vm_guest_run.sh +22 -2
  155. metadata +58 -3
  156. data/run_tests_vm.sh +0 -130
@@ -0,0 +1,202 @@
1
+ # Plan: registries for definitions that modules and custom.rb can change
2
+
3
+ TODO: not started. Act next on step 1 of "Implementation order".
4
+
5
+ ## Context
6
+
7
+ Several definition tables are Ruby constants, so nothing loaded later can change
8
+ them. A module can't add a key binding category, a setting to an existing
9
+ Settings section, or a context menu item. `custom.rb` can't rename or remove a
10
+ built-in one. When a module needs something like this today, it gets a special
11
+ case in core code: `all_settings_defs` (`gui_settings.rb`) builds the "Modules"
12
+ section, and `key_binding_category` (`key_bindings_report.rb`) makes the
13
+ automatic `module:<name>` category.
14
+
15
+ What a module adds must also go away when it is disabled. Today every module
16
+ does that cleanup by hand in `<name>_disable` (color_highlight, tts, ollama,
17
+ terminal, calculator, dictation), with `unbindkey` / `unreg_act` calls that have
18
+ to match its init code.
19
+
20
+ ## Which tables
21
+
22
+ Tables that something might reasonably want to change after they're defined:
23
+
24
+ | Kind | Table | File |
25
+ |---|---|---|
26
+ | list | `KEY_CATEGORIES` | `key_bindings_report.rb` |
27
+ | list | `BASIC_ACTIONS` | `key_bindings_report.rb` |
28
+ | list | `SETTINGS_DEFS` (sections and the settings in each) | `gui_settings.rb` |
29
+ | list | `CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION` | `gui_sourceview.rb` |
30
+ | map | `ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY` | `key_bindings_report.rb` |
31
+ | map | `KEY_CONDITIONS`, `KEY_MODE_NAMES` | `key_bindings_report.rb` |
32
+ | map | `SHEBANG_LANGS` | `buffer.rb` |
33
+ | map | `MARKUP_OVERLAY_STYLES` | `gui_settings.rb` |
34
+ | map | `ACTION_ALIASES` | `actions.rb` |
35
+
36
+ Borderline, decide when they come up: `TEXT_OBJECT_BRACKETS`,
37
+ `THEME_COLOR_DEFAULTS` / `CYBER_COLOR_DEFAULTS`, `VIM_BINDINGS`.
38
+ `GUESS_ENCODING_ORDER` is a user choice and belongs in `cnf`.
39
+
40
+ These stay constants. They are fixed facts, not definitions: `VOWELS`,
41
+ `CONSONANTS`, the LSP kind numbers (`COMPLETION_KINDS`, `FUNCTION_KINDS`,
42
+ `CLASS_KINDS`), `LSP_LANG`, `VIM_CONFLICT_WHY`, `DEMO_FILES`, the GUI size
43
+ defaults.
44
+
45
+ ## Design
46
+
47
+ ### 1. `Registry`: ordered entries by id
48
+
49
+ A new `lib/vimamsa/registry.rb` (add it to `rbvma.rb`). One class serves both
50
+ lists and maps: entries are kept in insertion order and keyed by id, and each
51
+ entry has a value plus the owner that added it.
52
+
53
+ ```ruby
54
+ r = vma.registry(:key_categories)
55
+
56
+ # one entry
57
+ r.add("ai", "AI assistant")
58
+
59
+ # several entries in one call: an Array of [id, value] pairs or a Hash
60
+ r.add([["ai", "AI assistant"], ["speech", "Speech"]])
61
+ vma.registry(:action_ns_category).add("ollama" => "ai", "tts" => "speech")
62
+
63
+ # entries whose value is a Hash of fields (settings, context menu)
64
+ vma.registry(:settings).add([:ollama, :model], section: "modules", label: "Model", type: :string)
65
+ vma.registry(:settings).add([
66
+ [[:ollama, :model], { section: "modules", label: "Model", type: :string }],
67
+ [[:ollama, :url], { section: "modules", label: "Server URL", type: :string }],
68
+ ])
69
+
70
+ r.remove("ai") # also: r.remove(["ai", "speech"])
71
+ r.replace("ai", "AI") # change the value and keep the position
72
+ r["ai"] # value, or nil
73
+ r.include?("ai")
74
+ r.each { |id, value| ... } # in order
75
+ r.ids, r.values, r.to_h
76
+ ```
77
+
78
+ Rules:
79
+
80
+ - `add` with an existing id is an error that names both owners, so two modules
81
+ don't overwrite each other without noticing. To change an entry on purpose,
82
+ use `replace`, or `remove` and then `add`.
83
+ - A batch `add` checks every entry before adding any of them: either the whole
84
+ batch goes in or nothing does.
85
+ - There are no ordering rules (`after:`/`before:`). Entries keep the order they
86
+ were added in, so built-in entries come first and those from modules and
87
+ custom.rb follow. Where position matters, a module reuses an existing entry
88
+ instead (e.g. puts its bindings in the `code` category) rather than adding
89
+ one.
90
+ - Values are stored as given; the registry doesn't copy or freeze them.
91
+
92
+ ### 2. Built-ins use the same API
93
+
94
+ Each table keeps its literal data in the file where it's defined, as the
95
+ initial entries:
96
+
97
+ ```ruby
98
+ define_registry(:key_categories, [
99
+ ["motion", "Moving the cursor"],
100
+ ["search", "Searching and jumping"],
101
+ ...
102
+ ])
103
+ ```
104
+
105
+ `define_registry` creates the registry with owner `"core"`. Built-in entries
106
+ aren't special, so custom.rb can `replace` or `remove` them. Code that read the
107
+ constant reads the registry. During the conversion the constant can stay as an
108
+ alias (`KEY_CATEGORIES = ...` replaced by a method) only where outside code
109
+ might use it; the codebase itself is switched over in the same step.
110
+
111
+ `SETTINGS_DEFS` becomes two registries: `:settings_sections` (id → label) and
112
+ `:settings` (key → fields including `section:`). A module can then add a
113
+ setting to an existing section such as Font, not only to "Modules", and the
114
+ special case in `all_settings_defs` goes away: the module loader registers each
115
+ module's enable switch.
116
+
117
+ ### 3. Owners, so disabling a module undoes it
118
+
119
+ Every `add` records the current owner, set the same way as
120
+ `KeyBindingTree#with_keywords`:
121
+
122
+ ```ruby
123
+ with_owner("module:ollama") { ollama_init } # done by the module loader
124
+ remove_owned("module:ollama") # done by the loader on disable
125
+ ```
126
+
127
+ - The loader already wraps module init (startup and Settings) and the three
128
+ places custom.rb runs in `with_keywords`; the same places set the owner
129
+ (`"module:<name>"`, `"custom"`). Outside them the owner is `"core"`.
130
+ - `remove_owned` removes that owner's entries from every registry, so modules
131
+ write no cleanup for registry entries.
132
+ - Later (step 6) `reg_act` and `bindkey` record the owner too, and
133
+ `remove_owned` also unregisters the actions and unbinds the keys. Then most
134
+ `<name>_disable` functions become unnecessary; a module keeps one only for
135
+ cleanup the registries don't know about (stopping a thread, closing a
136
+ window).
137
+ - `r.owner(id)` returns who added an entry, for error messages and debugging.
138
+
139
+ ### 4. Change listeners for consumers that cache
140
+
141
+ ```ruby
142
+ vma.registry(:context_menu).on_change { |reg| ... }
143
+ ```
144
+
145
+ runs after any `add`, `replace` or `remove` (once per batch call). Needed
146
+ where something is built once:
147
+
148
+ - the context menu creates its `Gio::SimpleAction`s in `init_context_menu`,
149
+ at startup;
150
+ - the Settings dialog builds its widgets when it opens, so it only needs to
151
+ rebuild if it's open.
152
+
153
+ The key bindings page reads the registries each time it's shown and needs no
154
+ listener.
155
+
156
+ ### 5. `cnf` stays separate
157
+
158
+ `cnf` holds the values the user chooses; registries hold what exists to choose
159
+ from. A setting's definition (label, type, range, section) goes in the
160
+ `:settings` registry, and its value stays in `cnf`.
161
+
162
+ ### 6. Discoverability
163
+
164
+ - `vma.registries` lists the registry names, so the command line can show
165
+ them (`:vma.registries`), and `vma.registry(:x).to_h` shows the contents.
166
+ - An unknown name in `vma.registry(:x)` is an error with a did-you-mean
167
+ suggestion (as for action ids), not a new empty registry, so a typo doesn't
168
+ fail silently. Registries are created only by `define_registry`.
169
+ - `custom_example.rb` gets a short example: rename a key binding category,
170
+ add a context menu item.
171
+
172
+ ## Implementation order
173
+
174
+ 1. `Registry`, `define_registry`, `vma.registry`, `with_owner` /
175
+ `remove_owned`, `on_change`, with single and batch `add`/`remove`.
176
+ Unit-style tests in `tests/test_registry.rb`: order, duplicate-id error with
177
+ owners, all-or-nothing batch, owner removal, listener called once per
178
+ batch, unknown-name error.
179
+ 2. Convert the key bindings page tables (`KEY_CATEGORIES`, `BASIC_ACTIONS`,
180
+ `ACTION_NS_CATEGORY`, `KEY_WORD_CATEGORY`, `KEY_MODE_CATEGORY`,
181
+ `KEY_CONDITIONS`, `KEY_MODE_NAMES`). They are new and used in one file. The
182
+ module loader sets the owner around module init and custom.rb. Test: a
183
+ module-owned category appears on the page and disappears after
184
+ `remove_owned`. `test_every_binding_has_a_category` keeps passing.
185
+ 3. Context menu (`CONTEXT_MENU_ITEMS`, `CONTEXT_MENU_ITEMS_SELECTION`), with
186
+ an `on_change` listener that creates the missing Gio actions. Test: an item
187
+ added after startup shows up in the menu and runs its action.
188
+ 4. `SETTINGS_DEFS` → `:settings_sections` + `:settings`; module enable
189
+ switches registered by the loader; `all_settings_defs` reads the
190
+ registries. Test: a module setting in an existing section is shown and
191
+ saved.
192
+ 5. `SHEBANG_LANGS`, `MARKUP_OVERLAY_STYLES`, `ACTION_ALIASES`.
193
+ 6. Owner tags on `reg_act` and `bindkey`; `remove_owned` unregisters and
194
+ unbinds them; remove the parts of `<name>_disable` that become
195
+ unnecessary. Test per module: enable, disable, and no actions, bindings or
196
+ registry entries of that module remain.
197
+
198
+ Run the full suite in the test VM after each step (`./run_tests_vm.rb`).
199
+
200
+ ## DONE
201
+
202
+ (nothing yet)
@@ -0,0 +1,97 @@
1
+ # Plan: faster startup
2
+
3
+ TODO: not started. Act next on step 1 of "Implementation order".
4
+
5
+ ## Context
6
+
7
+ Investigated 2026-11-21. Measured on the development machine, not the test VM: the VM
8
+ was at its login screen. The editor reached its first idle after about 2.6–3.0 s:
9
+ about 1.9 s loading code and about 0.9 s building the window and running `Editor#start`.
10
+ "Saves" below is the fastest of 5 runs, compared with the same version without the
11
+ change (`scripts/lib/perf_startup.rb`).
12
+
13
+ Tools:
14
+ - `ruby -r ./scripts/profile_startup.rb exe/vimamsa [file]` prints, at exit, the slow
15
+ requires and the slow calls of vimamsa's own methods, as trees with start offsets
16
+ and inclusive times. Method tracing starts once the code is loaded, so method times
17
+ are a bit too high.
18
+ - `./run_tests_vm.rb perf_startup [ref=REF] [runs=N]` compares startup time with
19
+ another commit. Use it to confirm each step.
20
+
21
+ ## Where the time goes
22
+
23
+ | Part | Time |
24
+ |---|---|
25
+ | `require "colors"` (the red-colors gem, required by cairo) | 0.6–0.8 s |
26
+ | The GTK typelibs (gdk4, gio2, pango, gsk4, gtk4, gtksourceview5) | ≈0.9 s |
27
+ | Other Ruby requires (listen, openssl, vimamsa's own files) | ≈0.3 s |
28
+ | `@window.show` (first realize, renderer setup) | ≈0.2 s |
29
+ | Key bindings (`bind_vim_bindings`: `bind_template`, `vim_keys_taken?`) | 0.13–0.2 s |
30
+ | Opening the file (`gui_set_file_lang` 72 ms) | ≈0.11 s |
31
+ | GC: 27 runs (7 major), mostly marking the GObject wrappers | ≈0.3 s in total |
32
+
33
+ ### What red-colors is
34
+
35
+ A color library from the Red Data Tools project. It has color models (RGB, HSL, HUSL,
36
+ XYZ, xyY, xterm256) with conversions, CSS/X11 color names, and the matplotlib and
37
+ seaborn colormaps (viridis, plasma, ...). When it is loaded,
38
+ `colors/colormap_data.rb` builds every colormap and a reversed copy of each:
39
+ thousands of `Colors::RGB` objects, many from Rationals. That is the slow part.
40
+
41
+ cairo loads it in `cairo/color.rb` only for `Cairo::Color.parse`, to turn a color
42
+ *name* into RGB. Hex strings and arrays don't need it. Vimamsa uses no colormaps.
43
+
44
+ ## Changes
45
+
46
+ ### Worth doing
47
+
48
+ 1. **Load red-colors only when it is used.** A shim `colors.rb` (e.g.
49
+ `lib/vimamsa/lazy/colors.rb`) does
50
+ `Object.autoload(:Colors, File.join(Gem::Specification.find_by_name("red-colors").full_gem_path, "lib/colors.rb"))`.
51
+ Put its dir first on `$LOAD_PATH` only around `require "gtk4"` in `rbvma.rb`, so
52
+ cairo's `require "colors"` gets the shim. If the gem spec can't be found (e.g. the
53
+ AppImage), skip the shim and load normally. Checked: `Cairo::Color.parse("red")`
54
+ and `"#ff0000"` still work. **Saves ≈0.5 s** (3.00 → 2.49 s).
55
+ 2. **GC off during startup.** `GC.disable` at the top of `exe/vimamsa`, and
56
+ `GC.enable` in the first idle after `Editor#start`. Peak memory is about 80 MB
57
+ higher until then. **Saves ≈0.24 s.** A larger initial heap
58
+ (`RUBY_GC_HEAP_*_INIT_SLOTS`) saved ≈0.1 s, but it must be set before Ruby
59
+ starts.
60
+ 3. **Load openssl only when it is needed.** `buffer.rb:5` requires `openssl` but
61
+ doesn't use it. `encrypt.rb` needs it only when a file is actually encrypted or
62
+ decrypted: require it inside those methods. Saves ≈0.05 s.
63
+ 4. **Remove `sleep(0.03)` in `Editor#start`** (`editor.rb:191`). Saves 0.03 s.
64
+ 5. **Start the `listen` file listener after the window is up** (an idle after
65
+ startup), or replace it with a GLib file monitor (`Gio::File#monitor_directory`).
66
+ Requiring it loads rb-inotify and ffi. Saves ≈0.08–0.15 s.
67
+ 6. **Reuse one `GtkSource::LanguageManager`.** `gui_set_file_lang` (`gui.rb:142`)
68
+ creates a new one on every call, which rescans the language files (72 ms). This
69
+ saves time for each extra file opened at startup and for every later file open.
70
+ 7. **Generate the style scheme once.** `load_vimamsa_scheme` and
71
+ `gui_apply_color_mode` run for each buffer and again in `gui_refresh_colors`:
72
+ three times at startup. Saves ≈0.04 s.
73
+
74
+ ### Possible, smaller or with trade-offs
75
+
76
+ - Optimize binding the key templates (`bind_template`, `vim_keys_taken?`): 0.1–0.2 s.
77
+ - Cache compiled Ruby code (as bootsnap does): compiling vimamsa's files takes ≈0.09 s
78
+ and loading them from binary ≈0.015 s, so at most ≈0.1 s. It adds complexity.
79
+ - `GSK_RENDERER=cairo` starts ≈0.18 s faster, but drawing is likely slower. Don't
80
+ make it the default.
81
+
82
+ ### Not worth it
83
+
84
+ - YJIT (`--yjit`): ≈0.35 s slower.
85
+ - `GSK_RENDERER=gl` / `vulkan`: 0.1–0.4 s slower than the default (ngl).
86
+ - The rest (the GTK typelibs and the first draw) can't be avoided from Ruby.
87
+
88
+ ## Implementation order
89
+
90
+ 1. Items 1–4. Confirm the gain with `./run_tests_vm.rb perf_startup ref=HEAD`, and
91
+ run the full suite in the VM.
92
+ 2. Items 5–7.
93
+ 3. Optionally, the key template binding.
94
+
95
+ ## DONE
96
+
97
+ (nothing yet)